tenantModule.directive("freeFieldComponent", ["$log", "$q", "$modal", "aresDialog", "aresNotification", "freeFieldSvc", "officeUtil", "enums", "dataDicSvc", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    return {
        restrict: "E",
        scope: {
            targetType: "@"
        },
        templateUrl: "/app/tenant/components/free-field-component/free-field-component.html",
        link: function(t) {
            var h = function(n, i) {
                    n.target.localName == "div" && ($(n.target).parents("ul").find("li").removeClass("selected"), $(n.target).parent("li").addClass("selected"), t.selectedItem = i, r())
                },
                r = function() {
                    t.selectedItem ? t.selectedItem.isInUse ? (t.moveLeftBtnState = !0, t.moveRightBtnState = !1) : (t.moveLeftBtnState = !1, t.moveRightBtnState = !0) : (t.moveLeftBtnState = !1, t.moveRightBtnState = !1);
                    t.moveLeftMultiBtnState = _.findIndex(t.freeFields, {
                        isInUse: !0
                    }) > -1 ? !0 : !1;
                    t.moveRightMultiBtnState = _.findIndex(t.freeFields, {
                        isInUse: !1
                    }) > -1 ? !0 : !1
                },
                c = function(i) {
                    if (!t.selectedItem) {
                        u.error("请选中" + t.fieldTitle);
                        return
                    }
                    if (t.selectedItem.isInUse != i) {
                        var e = _.find(t.freeFields, n => n.fieldCode.toLowerCase() == t.selectedItem.fieldCode.toLowerCase());
                        e && (e.isInUse = i, f.saveFreeFieldConfig(e).success(n => {
                            e.id = n.id, u.success("操作成功"), r(), s[t.dicName].refresh()
                        }).error(t => {
                            e.isInUse = !i, n.log(t), u.error("操作失败")
                        }))
                    }
                },
                l = function(i) {
                    if (i) {
                        if (!t.moveRightMultiBtnState) return
                    } else if (!t.moveLeftMultiBtnState) return;
                    angular.forEach(t.freeFields, n => {
                        n.isInUse = i
                    });
                    f.saveFreeFieldConfigs(t.freeFields).success(n => {
                        t.freeFields = n, t.selectedItem && (t.selectedItem = _.find(n, {
                            fieldCode: t.selectedItem.fieldCode
                        })), r(), s[t.dicName].refresh(), u.success("操作成功")
                    }).error(r => {
                        angular.forEach(t.freeFields, n => {
                            n.isInUse = !i
                        }), n.log(r), u.error("操作失败")
                    })
                },
                a = function(n) {
                    var r = i.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<free-field-edit-dialog><\/free-field-edit-dialog>",
                        controller: "FreeFieldEditDialogCtrl",
                        windowClass: "user-edit-dialog",
                        size: "sm",
                        resolve: {
                            host: function() {
                                return {
                                    freeField: angular.copy(n),
                                    isEditable: t.isEditable
                                }
                            }
                        }
                    });
                    r.result.then(function(n) {
                        if (n) {
                            var i = _.findIndex(t.freeFields, {
                                id: n.id
                            });
                            t.freeFields.splice(i, 1, n);
                            s[t.dicName].refresh()
                        }
                    })
                },
                v = function() {
                    t.freeFieldMaxCount = o.FreeFieldMaxCount.Default;
                    var n = parseInt(t.targetType);
                    switch (n) {
                        case o.FreeFieldTargetType.Patient:
                            t.fieldTitle = "患者自由项";
                            t.isShared = !0;
                            t.dicName = "patientFreeFieldConfigDic";
                            break;
                        case o.FreeFieldTargetType.Provider:
                            t.fieldTitle = "员工自由项";
                            t.isShared = !0;
                            t.dicName = "providerFreeFieldConfigDic";
                            t.freeFieldMaxCount = o.FreeFieldMaxCount.Provider;
                            break;
                        case o.FreeFieldTargetType.ChargeOrder:
                            t.fieldTitle = "收费单自由项";
                            t.isShared = !0;
                            t.dicName = "chargeOrderFreeFieldConfigDic"
                    }
                },
                y = function() {
                    v();
                    e.isRootGroup().then(function(i) {
                        var f, e, o;
                        for (t.isEditable = !t.isShared || i, f = [], e = 1; e <= t.freeFieldMaxCount; e++) o = {
                            isInUse: !1,
                            inputType: 0,
                            targetType: t.targetType
                        }, o.fieldName = "自由项" + e, o.seqNum = e, o.fieldCode = "Field" + e, f.push(o);
                        s[t.dicName].load().then(n => {
                            n && n.length > 0 && angular.forEach(n, n => {
                                var t = _.findIndex(f, t => t.fieldCode.toLowerCase() == n.fieldCode.toLowerCase());
                                t > -1 ? f.splice(t, 1, n) : f.splice(0, 1, n)
                            }), t.freeFields = f, r()
                        }, t => {
                            n.log(t), u.error("数据加载失败")
                        })
                    })
                };
            (function() {
                t.setThisSelected = h;
                t.changeFieldEnabled = c;
                t.changeThisTypeFieldsEnabled = l;
                t.editFreeField = a;
                y()
            })()
        }
    }
}]);
tenantModule.controller("FreeFieldEditDialogCtrl", ["$log", "$scope", "$modalInstance", "host", "practiceSvc", "aresNotification", "freeFieldSvc", function(n, t, i, r, u, f, e) {
    "use strict";
    var o = function() {
            if (t.isEditable = r.isEditable, t.freeField = r.freeField, t.dropDownValues = [], t.freeField.fieldValue) {
                var n = t.freeField.fieldValue.split("|");
                angular.forEach(n, n => {
                    t.dropDownValues.push({
                        value: n,
                        isShowDeleteBtn: !1
                    })
                });
                t.dropDownValues[t.dropDownValues.length - 1].isShowDeleteBtn = !0
            } else t.dropDownValues = [{
                value: "",
                isShowDeleteBtn: !1
            }];
            t.isShowAddBtn = t.dropDownValues.length < 50 ? !0 : !1
        },
        s = function() {
            for (var r, u, i = !1, n = 0; n < t.dropDownValues.length; n++)
                if (r = t.dropDownValues[n], u = _.filter(t.dropDownValues, {
                        value: r.value
                    }), u.length > 1) {
                    i = !0;
                    break
                }
            return i
        },
        h = function() {
            var u, o, r;
            if (!t.freeField.fieldName) {
                f.error("请输入自由项名称");
                return
            }
            if (t.freeField.fieldName.length > 15) {
                f.error("自由项名称最多只能输入15个字");
                return
            }
            if (t.freeField.inputType == 1) {
                if (u = _.find(t.dropDownValues, n => !n.value), u) {
                    f.error("请输入选项名称");
                    return
                }
                if (o = _.find(t.dropDownValues, n => n.value.length > 15), o) {
                    f.error("选项名称最多只能输入15个字");
                    return
                }
                if (s()) {
                    f.error("不允许有重复的选项卡");
                    return
                }
                if (r = "", angular.forEach(t.dropDownValues, n => {
                        r += n.value + "|"
                    }), r = r.substr(0, r.length - 1), r) t.freeField.fieldValue = r, t.freeField.inputTip = "";
                else {
                    f.error("请输入选项名称");
                    return
                }
            } else {
                if (t.freeField.inputTip && t.freeField.inputTip.length > 15) {
                    f.error("文本描述最多只能输入15个字");
                    return
                }
                t.freeField.fieldValue = ""
            }
            e.saveFreeFieldConfig(t.freeField).success(n => {
                i.close(n), f.success("操作成功")
            }).error(i => {
                i.name == "FreeFieldNameNotUniqueException" ? f.error("自由项名称【" + t.freeField.fieldName + "】已存在") : (n.log(i), f.error("操作失败"))
            })
        },
        c = function() {
            i.dismiss("cancel")
        };
    (function() {
        t.save = h;
        t.cancel = c;
        o()
    })()
}]);
tenantModule.directive("freeFieldEditDialog", ["$log", "$q", "$timeout", "aresNotification", function(n, t, i, r) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/tenant/components/free-field-component/free-field-edit-dialog.html",
        link: function(n, t) {
            var u = function() {
                    if (n.hasValue) {
                        r.error("不允许有重复的选项卡");
                        return
                    }
                    if (n.dropDownValues.length >= 50) {
                        r.error("最多只能添加50个选项");
                        return
                    }
                    angular.forEach(n.dropDownValues, n => {
                        n.isShowDeleteBtn = !1
                    });
                    n.dropDownValues.push({
                        value: "",
                        isShowDeleteBtn: !0
                    });
                    n.dropDownValues.length >= 50 && (n.isShowAddBtn = !1)
                },
                f = function(t) {
                    n.dropDownValues.splice(t, 1);
                    n.dropDownValues.length == 1 ? n.dropDownValues[0].isShowDeleteBtn = !1 : n.dropDownValues[n.dropDownValues.length - 1].isShowDeleteBtn = !0;
                    n.dropDownValues.length < 50 && (n.isShowAddBtn = !0)
                },
                e = function(t) {
                    var i = _.filter(n.dropDownValues, {
                        value: t
                    });
                    n.hasValue = i.length > 1 ? !0 : !1;
                    n.hasValue && r.error("【" + t + "】选项已存在")
                };
            (function() {
                n.addDropDownValue = u;
                n.removeValueItem = f;
                n.onFieldValueInputBlur = e;
                i(function() {
                    Ares.centerModal(t.closest(".modal-dialog"))
                }, 5)
            })()
        }
    }
}]);
tenantModule.directive("officeSettingApptBusinessRuleView", ["$log", "$timeout", "aresDialog", function(n, t, i) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/components/office-setting-appt-business-rule/office-setting-appt-business-rule-view.html",
        link: function(n, r) {
            var o = function(t) {
                    var i = t.sender;
                    /^\d{2}:\d{2}$/.test(n.officeSetting.reminderStartTime) || (n.officeSetting.reminderStartTime = "10:00", i.value("10:00"))
                },
                u = function(t) {
                    r.find("#" + t).kendoDropDownList({
                        optionLabel: "--请选择--",
                        dataTextField: "name",
                        dataValueField: "id",
                        dataSource: n.appointmentTemplates,
                        change: function(i, r) {
                            n.isChangeApp = !0;
                            var r = t.substr(20),
                                u = this.dataItem(i.item);
                            r ? n.shortMessageTemplates[r].shortMessageTemplate = u : n.defaultTemplate.shortMessageTemplate = u
                        }
                    })
                },
                f = function(t) {
                    r.find("#" + t).kendoDropDownList({
                        optionLabel: "-请选择-",
                        dataTextField: "itemName",
                        dataValueField: "id",
                        dataSource: n.patientTypes,
                        change: function() {
                            n.isChangeApp = !0
                        }
                    })
                },
                s = function() {
                    u("shortMessageTemplate");
                    n.shortMessageTemplates.forEach(function(n, t) {
                        f("patientType" + t);
                        u("shortMessageTemplate" + t)
                    })
                },
                h = function() {
                    n.onAddShortMessageTemplate = function() {
                        var r = n.shortMessageTemplates,
                            o, e;
                        if (r.length == n.patientTypes.length) {
                            i.info("提示", "添加的特殊模版不能大于患者类别个数!");
                            return
                        }
                        o = {
                            name: "删除",
                            id: "0",
                            shortMessageTemplate: {
                                content: ""
                            }
                        };
                        r.splice(r.length, 0, o);
                        e = r.length - 1;
                        t(function() {
                            f("patientType" + e);
                            u("shortMessageTemplate" + e)
                        })
                    };
                    n.onDelShortMessageTemplate = function(t) {
                        n.shortMessageTemplates.splice(t, 1);
                        n.isChangeApp = !0
                    }
                },
                c = function() {
                    var t = n.defaultTemplate,
                        i = r.find("#shortMessageTemplate"),
                        u = i.data("kendoDropDownList"),
                        f;
                    t ? i.length > 0 && i.val() != t.shortMessageTemplate.name && u && u.select(function(n) {
                        return n.name === t.shortMessageTemplate.name
                    }) : (f = _.find(n.appointmentTemplates, function(n) {
                        return n.name == "预约提醒"
                    }), n.defaultTemplate = {
                        shortMessageTemplate: f
                    }, u.select(function(n) {
                        return n.name == f.name
                    }));
                    n.shortMessageTemplates.forEach(function(n, t) {
                        var i = r.find("#patientType" + t).data("kendoDropDownList"),
                            u = r.find("#shortMessageTemplate" + t).data("kendoDropDownList");
                        i && i.select(function(t) {
                            return t.itemName === n.patientType
                        });
                        u && u.select(function(t) {
                            return t.name === n.shortMessageTemplate.name
                        })
                    })
                },
                l = function() {
                    s();
                    h();
                    c()
                },
                a = function() {
                    r.find("#apptSurveyTemplate").kendoDropDownList({
                        optionLabel: "--请选择--",
                        dataTextField: "name",
                        dataValueField: "id",
                        dataSource: n.allShortMessageTemplates
                    })
                },
                e = function(t) {
                    var i = r.find("#" + t);
                    i.kendoDropDownList({
                        optionLabel: "-请选择-",
                        dataTextField: "itemName",
                        dataValueField: "itemName",
                        dataSource: n.checkInTypes,
                        change: function() {
                            n.isCheckInChanged = !0
                        }
                    })
                },
                v = function() {
                    n.specialCheckInChargeItemTemplates.forEach(function(n, t) {
                        e("checkInType" + t)
                    })
                },
                y = function() {
                    n.onAddCheckInTemplate = function() {
                        var r = n.specialCheckInChargeItemTemplates,
                            u, f;
                        if (r.length == n.checkInTypes.length) {
                            i.info("提示", "添加的特殊模版不能大于挂号类型个数!");
                            return
                        }
                        u = {
                            chargeItemNames: n.parseDisplayNames([]),
                            chargeItems: [],
                            checkInType: "",
                            isDefault: !1
                        };
                        r.splice(r.length, 0, u);
                        f = r.length - 1;
                        t(function() {
                            e("checkInType" + f)
                        });
                        n.onDelCheckInTemplate = function(t) {
                            n.specialCheckInChargeItemTemplates.splice(t, 1)
                        }
                    }
                },
                p = function() {
                    v();
                    y()
                },
                w = function() {
                    l();
                    p();
                    a()
                };
            (function() {
                n.initViewHandleRegister(w);
                n.reminderStartTimeChange = o
            })()
        }
    }
}]);
tenantModule.directive("officeSettingChargeBusinessRuleView", ["$log", "$timeout", function() {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/components/office-setting-charge-business-rule/office-setting-charge-business-rule-view.html",
        link: function(n) {
            var t = function() {
                    n.onDeleteFreeField = function(t) {
                        n.chargeItemFreeFields.splice(t, 1)
                    };
                    n.onAddFreeField = function() {
                        var t = _.max(n.chargeItemFreeFields, function(n) {
                                return n.displayOrder
                            }),
                            i = t && t.displayOrder ? t.displayOrder + 1 : 1;
                        n.chargeItemFreeFields.push({
                            itemName: "",
                            itemType: "收费项目自由项",
                            itemValue: "",
                            displayOrder: i,
                            isEdit: !0,
                            isEmpty: !1
                        })
                    }
                },
                i = function() {
                    t()
                };
            (function() {
                n.initViewHandleRegister(i)
            })()
        }
    }
}]);
tenantModule.directive("officeSettingEditStarterView", ["$log", "$timeout", "$document", function(n, t, i) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/components/office-setting-edit-starter/office-setting-edit-starter-view.html",
        scope: {
            onStartEdit: "&",
            onSaveEdit: "&",
            onCancelEdit: "&"
        },
        link: function(n, r) {
            var u = !1,
                f, o = function() {
                    u = !0;
                    n.onStartEdit();
                    e()
                },
                s = function() {
                    n.onSaveEdit()
                },
                h = function() {
                    u = !1;
                    n.onCancelEdit();
                    e()
                },
                e = function() {
                    var n = r.find(".action-save"),
                        t = r.find(".action-cancel"),
                        i = r.find(".action-edit-start");
                    u ? (n.show(), t.show(), i.hide()) : (n.hide(), t.hide(), i.show())
                },
                c = function() {
                    var n = angular.element(i).find(".page-content");
                    n.on("scroll", l)
                },
                l = function() {
                    f && t.cancel(f);
                    f = t(function() {
                        var n = r.find(".office-setting-edit-starter"),
                            t = n.find(".config-top-bar");
                        n.offset().top <= 10 ? t.addClass("fix") : t.removeClass("fix")
                    }, 200)
                };
            (function() {
                e();
                c();
                n.onEditStart = o;
                n.onSave = s;
                n.onCancel = h
            })()
        }
    }
}]);
tenantModule.directive("officeSettingEditSwitch", ["$log", "$timeout", function() {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/tenant/components/office-setting-edit-switch/office-setting-edit-switch.html",
        scope: {
            boolValue: "=",
            ngDisabled: "=?"
        },
        link: function(n, t) {
            var i = [],
                r = function() {
                    var i = t.find(".content-block-switch-description"),
                        r = "",
                        u = "";
                    n.boolValue ? (i.text("启动"), r = "switch-enable", u = "switch-disabled") : (i.text("未启动"), r = "switch-disabled", u = "switch-enable");
                    i.removeClass(u).addClass(r)
                },
                u = function() {
                    n.$watch("boolValue", function() {
                        r();
                        n.$evalAsync(function() {
                            i.forEach(function(n) {
                                n()
                            })
                        })
                    })
                },
                f = function(n) {
                    angular.isFunction(n) && i.push(n)
                };
            (function() {
                n.updateEventHandleRegister = f;
                r();
                u()
            })()
        }
    }
}]);
tenantModule.controller("AccountAcceptanceCtrl", ["$log", "$scope", "$q", "practiceSvc", "loginContext", function(n, t, i, r, u) {
    "use strict";
    var e = u.officeId,
        f = function() {
            r.getFullOffice(e).success(function(n) {
                t.officeInfo = n
            })
        };
    (function() {
        f();
        t.browserOffice = f
    })()
}]);
practiceModule.controller("BaseDataConfigCtrl", ["$log", "$scope", "$q", "officeOptionSvc", function(n, t, i, r) {
    "use strict";
    var u = function() {
            var n = i.defer();
            return r.getOfficeOption(r.optionKeys.BaseDataConfig).then(function(i) {
                var r = JSON.parse(i);
                t.configs = angular.copy(r);
                n.resolve()
            }), n.promise
        },
        f = function() {
            r.setOfficeOption(r.optionKeys.BaseDataConfig, t.configs)
        },
        e = function() {
            t.configs.chargeItemRequired.procedureCode = !t.configs.chargeItemRequired.procedureCode
        };
    (function() {
        u();
        t.saveConfig = f;
        t.getConfig = u;
        t.onChargeItemProcedureCodeRequiredChanged = e
    })()
}]);
practiceModule.controller("FreeFieldConfigCtrl", ["$log", "$scope", "$filter", "$modal", "appNav", "practiceSvc", "providerSvc", "patientSvc", "dataDicSvc", "loginContext", "aresDialog", "formatUtil", "sessionCache", "appointmentSvc", "moduleOptionProvider", "officeOptionSvc", function() {
    "use strict";
    (function() {})()
}]);
tenantModule.controller("HandoverChargeDeductionCtrl", ["$log", "$scope", "$q", "loginContext", "$filter", "officeSelectorUtil", "moduleOptionProvider", "handOverSvc", "officeSvc", "aresNotification", "eventAggregator", "multiOfficeDataDic", "practiceSvc", "patientSvc", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v) {
    "use strict";
    var w = u("toSexString"),
        b = u("toAgeString"),
        k = u("toDeductionStepStateStr"),
        d = u("toLongDateTimeString"),
        g = function(n) {
            var u = i.defer(),
                n = n ? n : r.officeId;
            return l.loadDic(n, "doctorDic").then(function(n) {
                t.doctors = n;
                u.resolve(!0)
            }), u.promise
        },
        nt = function(n) {
            var u = i.defer(),
                n = n ? n : r.officeId;
            return l.loadDic(n, "consultantDic").then(function(n) {
                t.consultants = n;
                t.resetSelectedRows();
                u.resolve(!0)
            }), u.promise
        },
        tt = function() {
            var r = i.defer(),
                n = t.criteria;
            return n.startPayDateTime = t.timeSpan && t.timeSpan.startDate ? y(t.timeSpan.startDate) : null, n.endPayDateTime = t.timeSpan && t.timeSpan.endDate ? y(t.timeSpan.endDate, !0) : null, n.isGroup = t.isGroup, n.officeIds = t.selectedOfficeIds || [], r.resolve(n), r.promise
        },
        it = function(n, t, r) {
            var u = i.defer(),
                f;
            return n ? (f = angular.copy(r), f.selectAll = !0, o.searchChargeDeduction(f).success(function(n) {
                var t = [];
                n.items.forEach(function(n) {
                    t.push({
                        chargeOrderid: n.chargeOrderId,
                        groupIndex: n.groupIndex,
                        itemGroupIndex: n.itemGroupIndex
                    })
                });
                u.resolve(t)
            })) : u.resolve(t), u.promise
        },
        rt = function(n) {
            var r = i.defer();
            return tt(n).then(function(n) {
                o.searchChargeDeduction(n).success(function(n) {
                    et(n).then(function() {
                        r.resolve(t.pageData)
                    })
                })
            }), r.promise
        },
        y = function(n, t) {
            var n = moment(n).format("YYYY-MM-DD");
            return t && (n = moment(n).add(1, "day").format("YYYY-MM-DD")), n
        },
        p = function() {
            t.criteria = {
                payDateTime: moment(Ares.today()).format("YYYY-MM-DD"),
                isShow: !0,
                pageSize: 20,
                pageIndex: 1
            }
        },
        ut = function() {
            var n = i.defer();
            return s.getSelfAndChildOfficesByGroupId(r.officeId, e.isDescendantDataOpen()).success(function(i) {
                t.officeTreeData = f.setId(i);
                n.resolve(!0)
            }), n.promise
        },
        ot = function(n) {
            t.selectedOfficeIds = _.pluck(n, "officeId")
        },
        ft = function() {
            if (!t.timeSpan.startDate && !t.criteria.doctorId) return h.error("请输入开单时间或医生"), !1;
            if (r.isGroup && (t.selectedOfficeIds && t.selectedOfficeIds.length > 1 || !t.selectedOfficeIds || t.selectedOfficeIds && t.selectedOfficeIds.length == 0)) return h.error("仅支持单门店查询"), !1;
            var n = moment(t.timeSpan.startDate).add(1, "year").format("YYYY-MM-DD"),
                i = moment(t.timeSpan.endDate).add(1, "day").format("YYYY-MM-DD");
            return n < i ? (h.error("划扣执行交接查询时段不能超过1年"), !1) : !0
        },
        et = function(n) {
            var r = i.defer(),
                u = n && n.items ? _.pluck(n.items, "patientId") : [];
            return v.getPatientsHeadInfo(u).success(function(i) {
                var u, f;
                if (i)
                    for (u = 0; u < n.items.length; u++) f = _.find(i, function(t) {
                        return t.id == n.items[u].patientId
                    }), n.items[u].patientHead = f, n.items[u].sexStr = w(n.items[u].sex), n.items[u].ageStr = b(n.items[u].birth), n.items[u].stateStr = k(n.items[u].state), n.items[u].payDateTimeStr = d(n.items[u].payDateTime);
                t.pageData = n;
                r.resolve(!0)
            }), r.promise
        };
    (function() {
        t.refreshListData = rt;
        t.initDoctors = g;
        t.initConsultants = nt;
        t.initCriteria = p;
        t.queryOfficeTreePromise = ut;
        t.validateData = ft;
        t.isGroup = r.isGroup;
        t.officeOnly = !1;
        t.getSelectAllData = it;
        p()
    })()
}]);
tenantModule.controller("HandoverPatientCtrl", ["$log", "$scope", "$q", "loginContext", "$filter", "officeSelectorUtil", "handOverSvc", "officeSvc", "aresNotification", "eventAggregator", "multiOfficeDataDic", "practiceSvc", "moduleOptionProvider", "dataDicSvc", function(n, t, i, r, u, f, e, o, s, h, c, l, a) {
    "use strict";
    var p = u("toSexString"),
        et = u("toAgeString"),
        w = u("toLongDateTimeString"),
        b = function() {
            var r = i.defer(),
                n = t.criteria;
            return n.startRecordCreatedTime = t.timeSpan && t.timeSpan.startDate ? v(t.timeSpan.startDate) : null, n.endRecordCreatedTime = t.timeSpan && t.timeSpan.endDate ? v(t.timeSpan.endDate, !0) : null, n.isGroup = t.isGroup, n.officeIds = t.selectedOfficeIds || [], r.resolve(n), r.promise
        },
        k = function() {
            t.handoverType = [];
            t.criteria.dutyDoctorId && t.handoverType.push({
                id: 0,
                name: "责任医生"
            });
            t.criteria.consultantId && t.handoverType.push({
                id: 1,
                name: "咨询师"
            });
            t.criteria.onlineConsultantId && t.handoverType.push({
                id: 2,
                name: "网电咨询师"
            });
            t.criteria.attendantId && t.handoverType.push({
                id: 3,
                name: "专属客服"
            });
            t.criteria.developerId && t.handoverType.push({
                id: 5,
                name: "开发人员"
            });
            t.criteria.firstVisitDoctorId && t.handoverType.push({
                id: 6,
                name: "初诊医生"
            })
        },
        d = function(n) {
            var r = i.defer();
            return b(n).then(function(n) {
                if (!n.advisorId && !n.attendantId && !n.consultantId && !n.developerId && !n.dutyDoctorId && !n.onlineConsultantId && !n.firstVisitDoctorId) return s.error("医生,咨询师，网电咨询师，专属客服，专属顾问,开发人员,初诊医生必须至少选择一个"), r.promise;
                e.searchPatient(n).success(function(n) {
                    nt(n);
                    k();
                    t.pageData = n;
                    t.resetSelectedRows();
                    r.resolve(t.pageData)
                })
            }), r.promise
        },
        g = function(n, t, r) {
            var u = i.defer(),
                f;
            return n ? (f = angular.copy(r), f.selectAll = !0, e.searchPatient(f).success(function(n) {
                var t = [];
                n.items.forEach(function(n) {
                    t.push(n.id)
                });
                u.resolve(t)
            })) : u.resolve(t), u.promise
        },
        nt = function(n) {
            n && n.items && angular.forEach(n.items, function(n) {
                n.sexStr = p(n.sex);
                n.sourceTypeStr = "";
                n.sourceTypeLevel1 && (n.sourceTypeStr = n.sourceTypeLevel1);
                n.sourceType && (n.sourceTypeStr = n.sourceTypeStr + " | " + n.sourceType);
                n.refereeName && (n.sourceTypeStr = n.sourceTypeStr + " | " + n.refereeName);
                n.recordCreatedTimeStr = w(n.recordCreatedTime)
            })
        },
        v = function(n, t) {
            var n = moment(n).format("YYYY-MM-DD");
            return t && (n = moment(n).add(1, "day").format("YYYY-MM-DD")), n
        },
        y = function() {
            t.criteria = {
                pageSize: 20,
                pageIndex: 1
            }
        },
        tt = function() {
            var n = i.defer();
            return o.getSelfAndChildOfficesByGroupId(r.officeId, a.isDescendantDataOpen()).success(function(i) {
                t.officeTreeData = f.setId(i);
                n.resolve(!0)
            }), n.promise
        },
        it = function() {
            return r.isGroup && (t.selectedOfficeIds && t.selectedOfficeIds.length > 1 || !t.selectedOfficeIds || t.selectedOfficeIds && t.selectedOfficeIds.length == 0) ? (s.error("仅支持单门店查询"), !1) : !0
        },
        rt = function(n) {
            var u = i.defer(),
                f = a.isDescendantDataOpen() && r.isGroup ? !0 : !1;
            return l.listLiteProvidersByOffice(n, f, null).success(function(n) {
                n = _.filter(n, function(n) {
                    return n.id > 0
                });
                var i = _.filter(n, function(n) {
                    return !n.isInactive
                });
                t.developers = i;
                t.providers = n;
                u.resolve(!0)
            }), u.promise
        },
        ut = function(n) {
            n = n ? n : r.officeId;
            var u = [];
            return u.push(c.loadDic(n, "allConsultantDic").then(function(n) {
                t.consultants = n
            })), u.push(c.loadDic(n, "webPhoneConsultantDic").then(function(n) {
                t.onlineConsultants = ft(n)
            })), u.push(rt(n)), u.push(c.loadDic(n, "doctorDic").then(function(n) {
                t.doctors = n
            })), u.push(c.loadDic(n, "attendantDic").then(function(n) {
                t.attendants = n
            })), i.all(u)
        },
        ft = function(n) {
            return _.filter(n, function(n) {
                return !n.isInactive
            })
        };
    (function() {
        t.refreshListData = d;
        t.initCriteria = y;
        t.queryOfficeTreePromise = tt;
        t.validateData = it;
        t.initProviderBaseData = ut;
        t.isGroup = r.isGroup;
        t.officeOnly = !1;
        t.getSelectAllData = g;
        t.isAres3 = window.Ares3;
        y()
    })()
}]);
var tenant;
(function() {
    tenantModule.controller("MembershipCardNumberConfigCtrl", ["$q", "$scope", "officeSvc", "officeOptionSvc", "commonRuleUtil", "commonRuleSvc", "enums", function(n, t, i, r, u, f) {
        "use strict";
        var e = "MembershipCardNoGenMode",
            o = function() {
                var t = n.defer();
                return i.getOption(e).success(function(n) {
                    t.resolve(n)
                }), t.promise
            },
            s = function() {
                var t = n.defer();
                return f.getBySequenceType(50).success(function(n) {
                    t.resolve(n)
                }), t.promise
            },
            h = function() {
                return t.rule.id ? f.update(t.rule) : f.add(t.rule)
            },
            c = function() {
                var i = n.defer();
                return r.setOfficeOption(t.membershipCardNumConfig.optionKey, t.membershipCardNumConfig.optionValue).then(function() {
                    h().success(function(n) {
                        t.rule.id = n.id;
                        i.resolve()
                    })
                }), i.promise
            },
            l = function() {
                var i = n.defer();
                return o().then(function(n) {
                    t.membershipCardNumConfig = n || {
                        optionKey: e,
                        optionValue: 0
                    };
                    s().then(function(n) {
                        t.rule = n || u.getDefaultMembershipCardNumRule();
                        i.resolve()
                    })
                }), i.promise
            };
        (function() {
            t.initConfigData = l;
            t.saveConfig = c
        })()
    }])
})(tenant || (tenant = {}));
tenantModule.controller("officeAppointmentRequiredCtrl", ["$log", "$q", "$scope", "appNav", "officeSvc", "$timeout", "shortMessageSvc", "practiceSvc", "aresDialog", "loginContext", "officeOptionSvc", function(n, t, i, r, u, f, e, o, s, h, c) {
    "use strict";
    var a = function() {
            var n = t.defer();
            return c.getOfficeOption(c.optionKeys.AppointmentRequiredConfig).then(function(t) {
                var r = JSON.parse(t),
                    u = c.optionDefaultValues[c.optionKeys.AppointmentRequiredConfig],
                    f = JSON.parse(u);
                angular.forEach(f, function(n) {
                    var t = _.find(r, function(t) {
                        return t.name == n.name
                    });
                    t || r.push(n)
                });
                i.configs = angular.copy(r);
                n.resolve()
            }), n.promise
        },
        v = function() {
            c.setOfficeOption(c.optionKeys.AppointmentRequiredConfig, i.configs)
        },
        l = function() {
            return a()
        },
        y = function(n, t) {
            var r = i.configs.filter(function(t) {
                return t.name == n
            });
            r && r.length > 0 && (r[0].required = t)
        };
    (function() {
        i.configs = null;
        i.isEdit = !1;
        i.initData = l;
        i.saveConfig = v;
        i.onApptItemConfigChanged = y;
        l()
    })()
}]);
tenantModule.controller("officeChargeRequiredCtrl", ["$log", "$q", "$scope", "appNav", "officeSvc", "$timeout", "systemConfigSvc", "practiceSvc", "aresDialog", "loginContext", "officeOptionSvc", function(n, t, i, r, u, f, e, o, s, h, c) {
    "use strict";
    var a = [{
            name: "ApplyDetailCharge",
            text: "明细收费",
            isAllowed: !0
        }, {
            name: "ApplySimpleCharge",
            text: "简易收费",
            isAllowed: !0
        }, {
            name: "ApplyDisposalCharge",
            text: "处置收费",
            isAllowed: !0
        }, {
            name: "ApplyRCCharge",
            text: "跨科收费",
            isAllowed: !0
        }, ],
        b = function() {
            var n = t.defer();
            return e.getByType("Charge").then(function(t) {
                n.resolve(t.data)
            }), n.promise
        },
        k = function(n) {
            for (var t = 0; t < i.chargeTypes.length; t++)
                if (i.chargeTypes[t].text == n) {
                    i.currentSelectedType = i.chargeTypes[t].text;
                    v();
                    tt();
                    break
                }
        },
        d = function() {
            return b().then(function(n) {
                for (var r, u, f, e, t = 0; t < a.length; t++)
                    for (r = 0; r < n.length; r++)
                        if (u = a[t], f = n[r], u.name == f.configName) {
                            u.isAllowed = f.configValue.toLowerCase() == "true";
                            break
                        }
                for (i.chargeTypes = a, t = 0; t < a.length; t++)
                    if (e = a[t], e.isAllowed) {
                        i.currentSelectedType = e.text;
                        i.courrentIndex = t;
                        break
                    }
            })
        };
    i.requiredConfigs = null;
    var g = function() {
            var n = t.defer();
            return c.getOfficeOption(c.optionKeys.ChargeRequiredFieldConfig).then(function(n) {
                i.requiredConfigs = JSON.parse(n)
            }), n.resolve(), n.promise
        },
        nt = function() {
            return g().then(function() {
                v()
            })
        },
        v = function() {
            var r, e, n, s, t, u, f, o;
            if (i.commonChargeRequired = [], i.commonChargeGroupRequired = [], r = i.requiredConfigs, r && r.length > 0)
                for (e = 0; e < r.length; e++)
                    if (n = r[e], n.chargeType == i.currentSelectedType) {
                        if (s = n.common, t = s.split("&&"), t && t.length > 0)
                            for (u = 0; u < t.length; u++)
                                if (f = t[u].split("||"), f && f.length > 1)
                                    for (o = 0; o < f.length; o++) i.commonChargeGroupRequired.push(f[o]);
                                else i.commonChargeRequired.push(t[u]);
                        i.currentDeduction = n.deduction == undefined || n.deduction == null || n.deduction === "" ? !0 : n.deduction;
                        break
                    }
        },
        y = function(n, t) {
            if (n && n.length != 0)
                for (var i = 0; i < n.length; i++)
                    if (n[i] == t) {
                        n.splice(i, 1);
                        break
                    }
        },
        tt = function() {
            p(i.commonChargeGroupRequired);
            w(i.commonChargeRequired)
        },
        p = function(n) {
            if (i.requiredFiledList = angular.copy(l), n && n.length > 0)
                for (var t = 0; t < n.length; t++) y(i.requiredFiledList, n[t])
        },
        w = function(n) {
            if (i.groupRequiredFiledList = angular.copy(l), n && n.length > 0)
                for (var t = 0; t < n.length; t++) y(i.groupRequiredFiledList, n[t])
        },
        it = function(n, t, r) {
            var e = "",
                o, u, f;
            for (n && n.length > 0 && (e = n.join("&&") + "&&"), t && t.length > 0 && (o = t.join("||"), e += o), u = 0; u < i.requiredConfigs.length; u++)
                if (f = i.requiredConfigs[u], f.chargeType == i.currentSelectedType) {
                    f.common = e;
                    f.deduction = r;
                    break
                }
            c.setOfficeOption(c.optionKeys.ChargeRequiredFieldConfig, i.requiredConfigs)
        },
        rt = function() {
            return t.all([d(), nt()])
        },
        l = ["医生", "护士", "咨询师"],
        ut = angular.copy(l),
        ft = angular.copy(l),
        et = angular.copy(l),
        ot = [],
        st = [],
        ht = [];
    (function() {
        i.isEdit = !1;
        i.currentSelectedType = "";
        i.save = it;
        i.initData = rt;
        i.onChargeTypeSelect = k;
        i.requiredFiledList = ut;
        i.groupRequiredFiledList = ft;
        i.sourceFieldList = l;
        i.resetRequiredFieldList = p;
        i.resetGroupRequiredFiledList = w;
        i.deductionRequirdFiledList = et;
        i.commonChargeRequired = ot;
        i.commonChargeGroupRequired = st;
        i.deductionChargeRequired = ht
    })()
}]);
tenantModule.controller("OfficeCheckInRequiredCtrl", ["$log", "$q", "$scope", "appNav", "officeSvc", "$timeout", "shortMessageSvc", "practiceSvc", "aresDialog", "loginContext", "officeOptionSvc", function(n, t, i, r, u, f, e, o, s, h, c) {
    "use strict";
    var a = function() {
            var n = t.defer();
            return c.getOfficeOption(c.optionKeys.CheckInRequiredFieldConfig).then(function(t) {
                var r = JSON.parse(t);
                v(r);
                i.configs = angular.copy(r);
                n.resolve()
            }), n.promise
        },
        v = function(n) {
            var t = c.optionDefaultValues[c.optionKeys.CheckInRequiredFieldConfig],
                i = JSON.parse(t);
            angular.forEach(i, function(t) {
                var i = _.find(n, function(n) {
                    return n.name == t.name
                });
                i || n.push(t)
            })
        },
        y = function() {
            c.setOfficeOption(c.optionKeys.CheckInRequiredFieldConfig, i.configs)
        },
        l = function() {
            return a()
        },
        p = function(n, t) {
            var r = i.configs.filter(function(t) {
                return t.name == n
            });
            r && r.length > 0 && (r[0].required = t)
        };
    (function() {
        i.configs = null;
        i.isEdit = !1;
        i.initData = l;
        i.saveConfig = y;
        i.onCheckInItemConfigChanged = p;
        l()
    })()
}]);
practiceModule.controller("OfficeInfoEditCtrl", ["$log", "$scope", "$timeout", "dataDicSvc", "appNav", "officeSvc", "enums", "loginContext", "patientSvc", "practiceSvc", "eventAggregator", "aresNotification", function(n, t, i, r, u, f, e, o, s, h, c, l) {
    "use strict";
    var a = function() {
            var n = t.currentOffice.officeLocaltion ? t.currentOffice.officeLocaltion.location : null;
            if (t.isAllowAttendance && (n == " " || n == null)) {
                l.error("启用考勤时，地理位置不可为空。");
                return
            }
            f.updateFull(t.currentOffice).success(function(n) {
                r.officeDic.refreshItem(t.currentOffice);
                u.switchState("officeSettings.info", {});
                c.publish(c.events.OfficeChanged, t.currentOffice);
                n.isThisGivePoint && l.success("获得100积分")
            })
        },
        v = function(n) {
            var i = n ? n.id : 0;
            f.updatePicture(i).success(function() {
                t.currentOffice.pictureId = i;
                c.publish(c.events.OfficeChanged, t.currentOffice)
            })
        },
        y = function() {
            u.switchState("officeSettings.info", {})
        },
        p = function() {
            h.getFullOffice(t.officeId).success(function(n) {
                t.currentOffice = n;
                t.currentOffice.openTime = moment("2016-01-01 " + t.currentOffice.openTime).format("HH:mm");
                t.currentOffice.closeTime = moment("2016-01-01 " + t.currentOffice.closeTime).format("HH:mm")
            })
        },
        b = function(n) {
            n && s.getPictureById(n).success(function(n) {
                t.picture = n
            })
        },
        w = function() {
            h.getSystemConfigByName("IsAllowAttendance").success(function(n) {
                n && (t.isAllowAttendance = n.configValue.toUpperCase() == "TRUE" ? !0 : !1)
            })
        };
    (function() {
        t.initialize = !0;
        t.officeId = o.officeId;
        t.saveOffice = a;
        t.cancelOffice = y;
        t.updateOfficePicture = v;
        p();
        w()
    })()
}]);
practiceModule.controller("OfficeInfoCtrl", ["$log", "$scope", "$location", "$timeout", "$http", "$modal", "appNav", "practiceSvc", "patientSvc", "dataDicSvc", "enums", "constants", "loginContext", "mapUtil", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v) {
    "use strict";
    t.officeId = a.officeId;
    t.currentOffice = {};
    t.browserOfficeSetting = function() {
        o.getFullOffice(t.officeId).success(function(n) {
            t.currentOffice = n;
            t.currentOffice.openTime = moment("2016-01-01 " + t.currentOffice.openTime).format("HH:mm");
            t.currentOffice.closeTime = moment("2016-01-01 " + t.currentOffice.closeTime).format("HH:mm");
            n && n.officeLocaltion && n.officeLocaltion.lng ? (v.keys.lng = n.officeLocaltion.lng, v.keys.lat = n.officeLocaltion.lat) : (v.keys.address = n.province + n.city + n.district + n.address, v.keys.lng = 116.331398, v.keys.lat = 39.92556);
            v.keys.radius = n && n.officeLocaltion && n.officeLocaltion.radius ? n.officeLocaltion.radius : 500;
            v.loadBaiduMapSdkAsync()
        }).error(function(n) {
            t.data.error = n.data
        })
    };
    t.editOffice = function() {
        e.switchState("officeSettings.edit", {})
    };
    t.browserOfficeSetting(),
        function() {}()
}]);
practiceModule.controller("officeInvoiceEditCtrl", ["$log", "$scope", "$location", "$timeout", "$q", "officeSvc", function(n, t, i, r, u, f) {
    "use strict";
    var e = function() {
            var n = u.defer();
            return f.getOfficeInvoice().success(function(i) {
                t.invoice = i ? i : {
                    province: "",
                    city: "",
                    district: ""
                };
                n.resolve()
            }), n.promise
        },
        o = function() {
            if (!t.invoice.taxTitle) {
                t.showErrorNotification("请填写公司名称");
                return
            }
            if (!t.invoice.taxNo) {
                t.showErrorNotification("请填写纳税人识别号");
                return
            }
            f.updateOfficeInvoice(t.invoice).success(function(n) {
                t.invoice = n;
                t.edit()
            })
        };
    (function() {
        t.init = e;
        t.updateInvoice = o
    })()
}]);
tenantModule.controller("OfficeListCtrl", ["$log", "$scope", "$modal", "appNav", "dataDicSvc", "officeSvc", "enums", "aresDialog", function(n, t, i, r, u, f, e, o) {
    "use strict";
    var s = function() {
            f.list().success(function(n) {
                l(n);
                t.offices = n
            });
            f.getTenant().success(function(n) {
                var i = 0;
                i = n.maxNum == null ? 1 : n.maxNum;
                f.getOfficeList().success(function(n) {
                    var r = n.length;
                    t.minNum = r >= i ? 0 : i - r
                })
            })
        },
        h = function() {
            u.officeDic.refresh();
            s()
        },
        l = function(n) {
            angular.forEach(n, function(n) {
                n.isPatientPublicStr = n.isPatientPublic ? "是" : "否"
            })
        },
        a = function() {
            f.getTenant().success(function(n) {
                var t = 0;
                t = n.maxNum == null ? 1 : n.maxNum;
                f.getOfficeList().success(function(n) {
                    var i = n.length;
                    i >= t ? o.warn("提示", "您当前诊所数量已达到上限,请与领健公司联系") : c(f.adminOffice.id, e.ViewMode.Add)
                })
            })
        },
        v = function() {
            c(t.selectedItem.id, e.ViewMode.Edit)
        },
        c = function(n, t) {
            var r = i.open({
                animation: !0,
                backdrop: "static",
                template: "<office-edit-view><\/office-edit-view>",
                controller: "OfficeEditCtrl",
                windowClass: "small-dialog",
                size: "sm",
                resolve: {
                    host: function() {
                        return {
                            id: n,
                            viewMode: t
                        }
                    }
                }
            });
            r.result.then(function(n) {
                n && h()
            })
        },
        y = function() {
            t.selectedItem && o.confirm("删除诊所", "您确认要删除诊所【" + t.selectedItem.name + "】吗？").then(function() {
                f.logicDelete(t.selectedItem.id).success(function() {
                    h()
                })
            })
        };
    (function() {
        t.selectedItem = null;
        t.add = a;
        t.edit = v;
        t.destroy = y;
        s()
    })()
}]);
tenantModule.controller("OfficeOnliceConsultCreateFieldCtrl", ["$log", "$scope", "$timeout", "$q", "officeOptionSvc", "practiceSvc", function(n, t, i, r, u) {
    "use strict";
    var f = function() {
            var n = r.defer(),
                i = u.optionDefaultValues.OnlineConsultCreateInfoFieldsDefaultConfig;
            return t.OnlineConsultCreateInfoConfigFields = angular.copy(i), u.getOfficeOption(u.optionKeys.OnlineConsultCreateInfoFieldsConfig).then(function(i) {
                if (i) {
                    var r = JSON.parse(i);
                    t.OnlineConsultCreateInfoConfigFields.forEach(function(n) {
                        var t = _.find(r, {
                            name: n.name
                        });
                        t && (n.isEnabled = t.isEnabled, n.isRequired = t.isRequired)
                    });
                    n.resolve(t.OnlineConsultCreateInfoConfigFields)
                } else n.resolve(t.OnlineConsultCreateInfoConfigFields)
            }), n.promise
        },
        e = function() {
            var n = [];
            t.OnlineConsultCreateInfoConfigFields.forEach(function(t) {
                n.push({
                    name: t.name,
                    isEnabled: t.isEnabled,
                    isRequired: t.isRequired
                })
            });
            u.setOfficeOption(u.optionKeys.OnlineConsultCreateInfoFieldsConfig, n)
        };
    (function() {
        t.saveOnlineConsultCreateInfoFieldsConfig = e;
        t.getOnlineConsultCreateInfoFieldsConfig = f;
        f()
    })()
}]);
tenantModule.controller("OfficePatientFieldCtrl", ["$log", "$scope", "$timeout", "$q", "officeOptionSvc", "practiceSvc", function(n, t, i, r, u, f) {
    "use strict";
    var e = function() {
            var n = r.defer(),
                i = u.optionDefaultValues.PatientInfoFieldsDefaultConfig;
            return t.PatientInfoConfigFields = angular.copy(i), u.getOfficeOption(u.optionKeys.PatientInfoFieldsConfig).then(function(i) {
                if (i) {
                    var r = JSON.parse(i);
                    t.PatientInfoConfigFields.forEach(function(n) {
                        var t = _.find(r, {
                            name: n.name
                        });
                        t && (n.isEnabled = t.isEnabled, n.isRequired = t.isRequired, n.isTempPatientRequired = typeof t.isTempPatientRequired == "undefined" ? t.isRequired : t.isTempPatientRequired)
                    });
                    n.resolve(t.PatientInfoConfigFields)
                } else f.getSystemConfigByType("PatientRequired").success(function(i) {
                    angular.forEach(i, function(n) {
                        var i = _.find(t.PatientInfoConfigFields, {
                            name: n.configName
                        });
                        i && (i.isRequired = n.configValue.toUpperCase() == "TRUE", i.isTempPatientRequired = n.configValue.toUpperCase() == "TRUE")
                    });
                    n.resolve(t.PatientInfoConfigFields)
                })
            }), n.promise
        },
        o = function() {
            var n = [];
            t.PatientInfoConfigFields.forEach(function(t) {
                n.push({
                    name: t.name,
                    isEnabled: t.isEnabled,
                    isRequired: t.isRequired,
                    isTempPatientRequired: t.isTempPatientRequired
                })
            });
            u.setOfficeOption(u.optionKeys.PatientInfoFieldsConfig, n)
        };
    (function() {
        t.savePatientInfoFieldsConfig = o;
        t.getPatientInfoFieldsConfig = e;
        e()
    })()
}]);
tenantModule.controller("OfficePatientRequiredCtrl", ["$log", "$scope", "appNav", "officeSvc", "$timeout", "shortMessageSvc", "practiceSvc", "aresDialog", "loginContext", "officeOptionSvc", function(n, t, i, r, u, f, e) {
    "use strict";
    t.havePublicAccount = !1;
    t.havePrivateAccount = !1;
    var o = function() {
            angular.forEach(t.officeSetting, function(n) {
                n.configName == "patient" ? n.configValue = t.systemConfigs.patientName ? "true" : "false" : n.configName == "birthDay" ? n.configValue = t.systemConfigs.birthDay ? "true" : "false" : n.configName == "sex" ? n.configValue = t.systemConfigs.sex ? "true" : "false" : n.configName == "mobile" ? n.configValue = t.systemConfigs.mobile ? "true" : "false" : n.configName == "phoneNumber" ? n.configValue = t.systemConfigs.phoneNumber ? "true" : "false" : n.configName == "firstVisit" ? n.configValue = t.systemConfigs.firstVisit ? "true" : "false" : n.configName == "notes" ? n.configValue = t.systemConfigs.notes ? "True" : "false" : n.configName == "sourceType" ? n.configValue = t.systemConfigs.sourceType ? "true" : "false" : n.configName == "identityCard" ? n.configValue = t.systemConfigs.identityCard ? "true" : "false" : n.configName == "email" ? n.configValue = t.systemConfigs.email ? "true" : "false" : n.configName == "qq" ? n.configValue = t.systemConfigs.qq ? "true" : "false" : n.configName == "weixin" ? n.configValue = t.systemConfigs.weixin ? "true" : "false" : n.configName == "homeAddress" ? n.configValue = t.systemConfigs.homeAddress ? "true" : "false" : n.configName == "age" ? n.configValue = t.systemConfigs.age ? "true" : "false" : n.configName == "tags" && (n.configValue = t.systemConfigs.tags ? "true" : "false")
            });
            e.updateSystemConfigList(t.officeSetting).success(function() {
                t.isEdit = !t.isEdit
            })
        },
        s = function() {
            e.getSystemConfigByType("PatientRequired").success(function(n) {
                t.officeSetting = n;
                t.systemConfigs = {};
                var i = t.officeSetting;
                angular.forEach(t.officeSetting, function(n) {
                    n.configName == "patient" ? t.systemConfigs.patientName = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "birthDay" ? t.systemConfigs.birthDay = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "sex" ? t.systemConfigs.sex = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "mobile" ? t.systemConfigs.mobile = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "phoneNumber" ? t.systemConfigs.phoneNumber = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "firstVisit" ? t.systemConfigs.firstVisit = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "notes" ? t.systemConfigs.notes = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "sourceType" ? t.systemConfigs.sourceType = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "identityCard" ? t.systemConfigs.identityCard = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "email" ? t.systemConfigs.email = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "qq" ? t.systemConfigs.qq = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "weixin" ? t.systemConfigs.weixin = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "homeAddress" ? t.systemConfigs.homeAddress = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "age" ? t.systemConfigs.age = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "tags" && (t.systemConfigs.tags = n.configValue.toUpperCase() == "TRUE" ? !0 : !1)
                })
            })
        };
    (function() {
        t.save = o;
        s()
    })()
}]);
practiceModule.controller("officePointCtrl", ["$log", "$scope", "officeSvc", function(n, t, i) {
    "use strict";
    var r = function() {
            i.getOfficePointPair().then(function(n) {
                t.currentPoint = n.data.currentPoint;
                t.nearExpirePoint = n.data.nearExpirePoint
            })
        },
        u = function() {
            t.expireTime = (new Date).getFullYear() + ".12.31";
            r()
        };
    (function() {
        u()
    })()
}]);
tenantModule.controller("officeTodayworkManagementCtrl", ["$log", "$q", "$scope", "appNav", "officeSvc", "$timeout", "shortMessageSvc", "practiceSvc", "aresDialog", "loginContext", "officeOptionSvc", function(n, t, i, r, u) {
    "use strict";
    var e = function() {
            angular.forEach(i.officeSetting.systemConfigs, function(n) {
                n.configName == "DefaultIncludeCharged" && (n.configValue = i.systemConfigs.DefaultIncludeCharged)
            });
            u.updateOfficeSetting(i.officeSetting).success(function() {
                i.isEdit = !i.isEdit
            })
        },
        f = function() {
            return o()
        },
        o = function() {
            var n = t.defer();
            return u.getOfficeSetting().success(function(t) {
                i.officeSetting = t;
                i.systemConfigs = {};
                var r = i.officeSetting.systemConfigs;
                angular.forEach(i.officeSetting.systemConfigs, function(n) {
                    n.configName == "DefaultIncludeCharged" && (i.systemConfigs.DefaultIncludeCharged = n.configValue.toUpperCase() == "TRUE" ? !0 : !1)
                });
                n.resolve()
            }), n.promise
        };
    (function() {
        i.isEdit = !1;
        i.isChangeApp = !1;
        i.saveConfig = e;
        i.initData = f;
        f()
    })()
}]);
tenantModule.controller("PartnerAccountManagementCtrl", ["$log", "$scope", "partnerSvc", "aresNotification", function(n, t, i, r) {
    "use strict";
    var u = function() {
            var n = {
                name: t.searchKeyWord,
                account: t.searchKeyWord,
                mobile: t.searchKeyWord,
                pageIndex: t.pageIndex,
                pageSize: t.pageSize
            };
            i.searchAccount(n).then(function(n) {
                t.result = n.data;
                angular.forEach(t.result.items, function(n, i) {
                    n.order = i + 1 + (t.result.pageIndex - 1) * t.result.pageSize
                })
            })
        },
        f = function(n, t) {
            var f = {
                id: n,
                IsDisabled: t
            };
            i.disableAccount(f).then(function(n) {
                n && (r.success("操作成功"), u())
            })
        };
    (function() {
        t.search = u;
        t.disableAccount = f;
        t.pageIndex = 1;
        t.pageSize = 10;
        u()
    })()
}]);
practiceModule.controller("ProviderAppendCtrl", ["$log", "$scope", "$filter", "$modalInstance", "providerSvc", "dataDicSvc", "loginContext", "aresDialog", "host", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    var a = i("toSexString"),
        v = i("toOfficeAbbr"),
        c = function() {
            var n = _.clone(t.criteria);
            n.withWorkOffices = !0;
            n.withUserInfo = !0;
            u.search(n).success(function(n) {
                for (var r, i = 0; i < n.length; i++) r = n[i], h(r);
                t.providers = n
            })
        },
        h = function(n) {
            n.sexStr = a(n.sex);
            n.officeName = v(n.officeId);
            var i = _.map(n.workingOffices, function(n) {
                    return n.name
                }),
                r = i.join(",");
            n.workingOfficeStr = r;
            n.isWorkingInCurrentOffice = _.find(n.workingOffices, {
                id: t.officeId
            }) != null;
            y(n)
        },
        y = function(n) {
            var t = n.user,
                i, r;
            t ? (i = _.map(t.roles, function(n) {
                return n.name
            }), r = i.join(","), t.roleStr = r) : n.user = {}
        },
        l = function(n) {
            var i = t.providers,
                u = _.find(i, function(t) {
                    return t.id === n.id
                }),
                r = i.indexOf(u);
            r >= 0 && i.splice(r, 1, n)
        },
        p = function(n) {
            n = parseInt(n);
            var i = _.find(t.providers, {
                id: n
            });
            i && o.confirm("确认", "您确定要授权员工【" + i.name + "】到诊所【" + t.office.name + "】工作么？").then(function() {
                u.appendWorkingOffice(n, t.officeId).success(function(n) {
                    t.hasChanged = !0;
                    h(n);
                    l(n);
                    t.refreshGrid()
                })
            })
        },
        w = function(n) {
            n = parseInt(n);
            var i = _.find(t.providers, {
                id: n
            });
            i && o.confirm("确认", "您确定要取消员工【" + i.name + "】在诊所【" + t.office.name + "】的工作授权么？").then(function() {
                u.removeWorkingOffice(n, t.officeId).success(function(n) {
                    t.hasChanged = !0;
                    h(n);
                    l(n);
                    t.refreshGrid()
                })
            })
        },
        b = function() {
            t.hasChanged ? r.close() : r.dismiss("cancel")
        },
        k = function() {
            t.officeId = s.officeId || e.officeId;
            t.office = f.officeDic.getItemSync(t.officeId);
            var n = {
                officeId: null,
                name: null,
                excludedOfficeId: t.officeId,
                isInactive: !1,
                isShow: !0
            };
            t.criteria = n;
            c()
        };
    (function() {
        t.hasChanged = !1;
        t.search = c;
        t.cancel = b;
        t.appendProvider = p;
        t.removeProvider = w;
        k()
    })()
}]);
practiceModule.controller("ProviderEditCtrl", ["$log", "$scope", "$location", "$q", "$http", "$state", "aresDialog", "appNav", "practiceSvc", "dataDicSvc", "loginContext", "freeFieldSvc", "officeSvc", "enums", "constants", "userOptionSvc", "providerPictureSvc", "moduleOptionProvider", "officeOptionSvc", "shortMessageSvc", "hebeBusinessPortal", "aresNotification", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p, w, b, k, d, g, nt) {
    "use strict";
    var et = window.location.hostname,
        ot = et.split(".")[0],
        st = function() {
            t.providerId = f.params.providerId;
            var n = [];
            return t.providerId > 0 ? (n.push(at(t.providerId)), n.push(ht()), n.push(lt())) : n.push(ct()), r.all(n)
        },
        ht = function() {
            return s.getProvider(t.providerId).then(function(n) {
                t.currentProvider = n.data
            }).then(function() {
                if (!t.currentProvider.employeeNo || t.currentProvider.employeeNo == "") return s.generateEmployeeNo().then(function(n) {
                    var i = n.data;
                    t.currentProvider.employeeNo = i
                })
            }).catch(function(n) {
                var i = n.data;
                t.data.error = i.data
            })
        },
        ct = function() {
            var n = r.defer(),
                i = f.params.officeId || c.officeId,
                u = _.find(t.offices, function(n) {
                    return n.id == i
                });
            return t.currentProvider = {
                sex: v.SexType.Unknown,
                job: "医生",
                show: !0,
                officeId: i,
                user: {
                    isNeedExtraValidate: 0,
                    isNeedDeviceValidate: 0,
                    isMobileAppDisabled: 0
                },
                workingOffices: [u]
            }, t.providerFreeField = {
                targetType: 2
            }, t.pictures = [{
                title: "医师照片",
                proivderPictureType: 1
            }, {
                title: "医师执业证首页",
                proivderPictureType: 2
            }, {
                title: "医师执业证个人信息页",
                proivderPictureType: 3
            }, {
                title: "医师签名",
                proivderPictureType: 4
            }], s.generateEmployeeNo().success(function(i) {
                t.currentProvider.employeeNo = i;
                n.resolve()
            }), n.promise
        },
        lt = function() {
            var n = r.defer();
            return w.getProviderPictures(t.providerId).success(function(i) {
                i ? (tt(i, 1, "医师照片"), tt(i, 2, "医师执业证首页"), tt(i, 3, "医师执业证个人信息页"), tt(i, 4, "医师签名"), i = _.sortBy(i, "proivderPictureType"), t.pictures = i) : t.pictures = [{
                    title: "医师照片",
                    proivderPictureType: 1
                }, {
                    title: "医师执业证首页",
                    proivderPictureType: 2
                }, {
                    title: "医师执业证个人信息页",
                    proivderPictureType: 3
                }, {
                    title: "医师签名",
                    proivderPictureType: 4
                }];
                n.resolve()
            }), n.promise
        },
        at = function(n) {
            var i = r.defer();
            return l.getProviderFreeFieldValue(n).success(function(r) {
                t.providerFreeField = r || {
                    targetType: 2,
                    targetId: n
                };
                i.resolve()
            }), i.promise
        },
        it = function() {
            var i = r.defer();
            return Ares.ensureNotDuplicated("SendShortMessage") ? !t.needSendMessage || !t.canEditUser || t.currentProvider.isMobileVerified || !t.currentProvider.mobile ? (i.resolve(), i.promise) : (d.getProviderInviteMessage().success(function() {
                var r = t.currentProvider.user,
                    u = "恭喜您开通e看牙saas员工账号，公司代码" + ot + "，用户名" + r.account + "，初始密码" + r.password + "，请登录系统修改密码。移动办公请下载e看牙App：https://shence.linkedcare.cn:8106/r/r",
                    f = {
                        templateId: 0,
                        patientId: 0,
                        patientName: "",
                        patientNameCode: "",
                        mobile: t.currentProvider.mobile,
                        content: u
                    };
                d.sendMessage(f).success(function(n) {
                    var r = !n.errorCode || n.errorCode == "";
                    t.sentMessage = n;
                    r ? t.status = "succeeded" : (t.status = "failed", t.errorCode = n.errorCode, t.errorMessage = n.errorMessage);
                    i.resolve()
                }).error(function(r) {
                    n.debug("send short message failed!");
                    n.error(JSON.stringify(r));
                    t.status = "failed";
                    r.name == "ShortMessageAccountException" ? e.warn("错误", r.message) : r.name == "AresMessageInvalidException" && (t.status = null, e.warn("错误", "消息内容" + r.message));
                    i.resolve()
                })
            }), i.promise) : (i.resolve(), i.promise)
        },
        rt = function() {
            wt() && l.saveFreeField(t.providerFreeField).success(function(n) {
                t.providerFreeField = n
            })
        },
        vt = function() {
            t.currentProvider.needSendMessage = t.needSendMessage;
            t.currentProvider.id > 0 ? s.updateProvider(t.currentProvider).success(function(n) {
                it().then(function() {
                    rt();
                    ut(n.job);
                    yt(n.userID);
                    o.switchState("providerSettings.providerList", {})
                })
            }).error(function(n) {
                n.name === "AccountNotUniqueException" && e.warn("提示", "登录账号已经存在！");
                n.name === "EmployeeNoNotUniqueException" && e.warn("提示", "员工号已经被使用,请更换后保存！");
                n.name === "ProviderNameNoNotUniqueException" && e.warn("提示", "姓名已经被使用,请更换后保存！")
            }) : s.createProvider(t.currentProvider).success(function(n) {
                it().then(function() {
                    _.each(t.pictures, function(t) {
                        t.providerId = n.id
                    });
                    t.providerFreeField.targetId = n.id;
                    rt();
                    w.updateProviderPictures(t.pictures);
                    ut(n.job);
                    o.switchState("providerSettings.providerList", {})
                })
            }).error(function(n) {
                n.name === "AccountNotUniqueException" && e.warn("提示", "登录账号已经存在！");
                n.name === "EmployeeNoNotUniqueException" && e.warn("提示", "员工号已经被使用，请更换后保存！");
                n.name === "ProviderNameNoNotUniqueException" && e.warn("提示", "姓名已经被使用,请更换后保存！")
            })
        },
        ut = function() {
            h.doctorDic.refresh();
            h.assistantDic.refresh();
            h.nurseDic.refresh();
            h.consultantDic.refresh();
            h.attendantDic.refresh();
            h.webPhoneConsultantDic.refresh();
            h.currentOfficeWorkProviderDic.refresh();
            h.allProviderDic.refresh();
            h.userNameDic.refresh();
            h.payeeDic.refresh();
            h.groupConsultantDic.refresh();
            h.workflowApprovalProviderDic.refresh()
        },
        yt = function(n) {
            if (n == c.userId) {
                var t = p.userOptionKey.discountLimit;
                p.clearUserOption(t)
            }
        },
        pt = function() {
            t.currentProvider = {};
            o.switchState("providerSettings.providerList", {})
        },
        wt = function() {
            for (var r, i = !1, n = 1; n <= v.FreeFieldMaxCount.Provider; n++)
                if (r = "field" + n, t.providerFreeField && t.providerFreeField[r] !== undefined) {
                    i = !0;
                    break
                }
            return i
        },
        tt = function(n, t, i) {
            var r = _.find(n, {
                proivderPictureType: t
            });
            r ? r.title = i : n.push({
                title: i,
                proivderPictureType: t
            })
        },
        bt = function(n) {
            var i, r;
            n && (i = _.find(t.pictures, {
                proivderPictureType: parseInt(n.type)
            }), n.delete && i && i.id > 0 ? w.deleteProviderPicture(i.id).then(function() {
                i.id = 0;
                i.pictureId = 0;
                i.providerId = 0;
                h.providerPictureDic.refresh()
            }) : (r = {
                id: i ? i.id : 0,
                providerId: t.currentProvider.id,
                pictureId: n.id,
                proivderPictureType: n.type
            }, w.updateProviderPicture(r).success(function(n) {
                var i = _.find(t.pictures, {
                    proivderPictureType: parseInt(r.proivderPictureType)
                });
                i && n && (i.id = n.id, i.pictureId = n.pictureId, i.providerId = n.providerId);
                h.providerPictureDic.refresh()
            })))
        },
        kt = function() {
            var i = h.officeSettingDic.load().then(function(n) {
                    t.isConnectYongyouHrp = n.isConnectYonyouHrp;
                    t.isInternWorkflowEnabled = n.isInternWorkflowEnabled
                }),
                u = h.roleDic.load().then(function(n) {
                    t.roles = n
                }),
                f = h.officeDic.loadActive().then(function(n) {
                    t.offices = n
                }),
                e = h.jobDic.load().then(function(n) {
                    t.jobs = n
                }),
                o = h.doctorDic.loadActive().then(function(n) {
                    t.doctors = n
                }),
                c = h.providerDic.loadActive().then(function(n) {
                    t.providers = n
                }),
                l = s.getDepartment().then(function(n) {
                    t.departments = n.data
                }),
                n;
            return t.workingOfficesEdit = t.$root.isTenantAdmin, n = k.getOfficeOption("IsHealthBureauDataExportEnabled_Shenzhen").then(function(n) {
                t.szHealthInspectorEnabled = n
            }), r.all([e, u, o, f, i, c, l, dt(), n, ])
        },
        ft = function(n, t) {
            n.items && angular.forEach(n.items, function(n) {
                n.hasChildren || n.isGroup ? ft(n, t) : t.push(n)
            })
        },
        dt = function() {
            var n = r.defer();
            return a.getSelfAndChildOfficesByGroupId(-1e3, !0).success(function(i) {
                var r = i,
                    u, f;
                i.length === 1 && i[0].officeId == -1e3 && (r = i[0].items);
                r && r.length > 0 && (u = [], ft(r[0], u), t.officeTreeData = r, f = _.pluck(u, "officeId"), t.defaultOfficeIds = f, t.selectedOfficeIds = []);
                n.resolve(!0)
            }), n.promise
        },
        gt = function() {
            var n = g.openDoctorCertificateModal(t.providerId);
            n.result.then(function(n) {
                n && nt.success("保存成功！")
            })
        };
    (function() {
        t.saveProvider = vt;
        t.cancelProvider = pt;
        t.updateProviderPicture = bt;
        t.openDoctorCertificateModal = gt;
        kt().then(function() {
            return st()
        }).then(function() {
            t.initView()
        })
    })()
}]);
practiceModule.controller("ProviderListCtrl", ["$log", "$scope", "$filter", "$modal", "appNav", "practiceSvc", "providerSvc", "patientSvc", "dataDicSvc", "loginContext", "aresDialog", "formatUtil", "sessionCache", "appointmentSvc", "moduleOptionProvider", "officeOptionSvc", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v) {
    "use strict";
    var y = a.getCache(a.keys.ProviderListSearchCriteria),
        d = i("toSexString"),
        g = i("toDateString"),
        nt = i("toOfficeAbbr"),
        tt = function() {
            var n = {
                    isWorkingOffice: !1,
                    isInactive: !1,
                    includeLeft: !1
                },
                i = y.loadObject();
            i && _.extend(n, i);
            h.isTenantAdmin || (n.selectedOfficeId = h.officeId, n.isWorkingOffice = !0);
            t.criteria = n
        },
        p = function() {
            var n = _.clone(t.criteria);
            y.saveObject(n);
            n.isWorkingOffice ? n.workingOfficeId = n.selectedOfficeId : n.officeId = n.selectedOfficeId;
            n.hasAccount || (n.hasAccount = null);
            n.isShow = n.includeLeft ? null : !0;
            n.withWorkOffices = !0;
            n.withUserInfo = !0;
            e.search(n).success(function(n) {
                for (var r, i = 0; i < n.length; i++) r = n[i], k(r);
                t.providers = it(n)
            })
        },
        w = function() {
            p()
        },
        it = function(n) {
            return _.filter(n, function(n) {
                if (!t.criteria || !t.criteria.searchName && !t.criteria.employeeNo && !t.criteria.mobile && !t.criteria.account) return !0;
                var i = !0;
                return t.criteria.searchName && (i = i && (n.nameCode && n.nameCode.indexOf(t.criteria.searchName) > -1 || n.name.indexOf(t.criteria.searchName) > -1)), t.criteria.employeeNo && (i = i && n.employeeNo && n.employeeNo.indexOf(t.criteria.employeeNo) > -1), t.criteria.mobile && (i = i && n.mobile && n.mobile.indexOf(t.criteria.mobile) > -1), t.criteria.account && (i = i && n.user.account && n.user.account && n.user.account.indexOf(t.criteria.account) > -1), i
            })
        },
        k = function(n) {
            n.sexStr = d(n.sex);
            n.birthStr = g(n.birth);
            n.officeName = nt(n.officeId);
            n.show == null && (n.show = !0);
            n.showStr = n.show ? "在职" : "离职";
            var t = _.map(n.workingOffices, function(n) {
                    return n.abbreviation
                }),
                i = t.join(",");
            n.workingOfficeStr = i;
            rt(n)
        },
        rt = function(n) {
            var t = n.user,
                i, r;
            t ? (i = _.map(t.roles, function(n) {
                return n.name
            }), r = i.join(","), t.roleStr = r) : n.user = {}
        },
        ut = function(n) {
            u.switchState("providerSettings.providerEdit", {
                providerId: n
            })
        },
        ft = function(n) {
            var t = b(n),
                i = "";
            v.hasAppointmentByDoctorId(n).success(function(r) {
                if (r) {
                    c.info("系统提示", "不能删除，此员工有未完成的预约。");
                    return
                }
                i = t && t.user && t.user.id ? "员工删除后，对应的用户账号【" + t.user.account + "】将不能登录，确定要删除此员工信息？" : "确定要删除员工【" + t.name + "】？";
                c.confirm("确认", i).then(function() {
                    et(n)
                })
            })
        },
        et = function(n) {
            f.deleteProvider(n).success(function() {
                for (var r, i = 0; i < t.providers.length; ++i) t.providers[i].id == n && (r = t.providers[i], t.providers.splice(i, 1), w(), ot(r.job))
            });
            f.deleteScheduleById(n).success(function() {})
        },
        ot = function(n) {
            n == "医生" ? s.doctorDic.refresh() : n == "牙医助理" ? s.assistantDic.refresh() : n == "咨询师" ? (s.consultantDic.refresh(), s.attendantDic.refresh()) : n == "护士" ? s.nurseDic.refresh() : n == "客服" && s.attendantDic.refresh();
            s.payeeDic.refresh()
        },
        st = function() {
            u.switchState("providerSettings.providerEdit", {
                providerId: 0,
                officeId: t.criteria.selectedOfficeId
            })
        },
        b = function(n) {
            n = parseInt(n);
            return _.find(t.providers, {
                id: n
            })
        },
        ht = function(n) {
            var r = b(n.id),
                i = t.providers.indexOf(r);
            i >= 0 && t.providers.splice(i, 1, n);
            s.payeeDic.refresh()
        },
        ct = function(n) {
            var t = b(n),
                i;
            t && t.user && t.user.id && (i = r.open({
                animation: !0,
                backdrop: "static",
                template: "<user-password-edit-view><\/user-password-edit-view>",
                controller: "UserPasswordEditCtrl",
                windowClass: "small-dialog",
                size: "sm",
                resolve: {
                    host: function() {
                        return {
                            id: t.user.id,
                            account: t.user.account,
                            isAdminEdit: !0
                        }
                    }
                }
            }), i.result.then(function() {
                c.info("系统提示", "密码修改成功")
            }))
        },
        lt = function() {
            var n = r.open({
                animation: !0,
                backdrop: "static",
                template: "<provider-append-view><\/provider-append-view>",
                controller: "ProviderAppendCtrl",
                size: "lg",
                windowClass: "xl-dialog",
                resolve: {
                    host: function() {
                        return {
                            officeId: t.officeId || h.officeId
                        }
                    }
                }
            });
            n.result.then(function() {
                w()
            })
        },
        at = function(n) {
            var r = s.officeDic.getItemSync(t.officeId),
                i;
            n = parseInt(n);
            i = _.find(t.providers, {
                id: n
            });
            i && c.confirm("确认", "您确定要取消员工【" + i.name + "】在诊所【" + r.name + "】的工作授权么？").then(function() {
                e.removeWorkingOffice(n, t.officeId).success(function(n) {
                    k(n);
                    ht(n);
                    w()
                })
            })
        },
        vt = function() {
            s.officeSettingDic.load().then(function(n) {
                t.isConnectYongyouHrp = n.isConnectYonyouHrp
            })
        };
    (function() {
        t.pageStateCache = y;
        t.officeId = h.officeId;
        t.isWorkingOffice = !1;
        t.createProvider = st;
        t.deleteProvider = ft;
        t.editProvider = ut;
        t.changePwd = ct;
        t.appendProvider = lt;
        t.removeProvider = at;
        t.search = p;
        vt();
        tt();
        p()
    })()
}]);
tenantModule.controller("RoleListCtrl", ["$log", "$scope", "$modal", "loginContext", "appNav", "dataDicSvc", "roleSvc", "aresDialog", "userOptionSvc", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    var h = function() {
            f.roleDic.load().then(function(n) {
                t.roles = n
            })
        },
        l = function(n) {
            n && (t.toBeSelectedRoleId = n.id);
            f.roleDic.clearCache();
            h()
        },
        a = function(n) {
            e.create(n).success(function(n) {
                c(n)
            }).error(function() {
                t.refreshGrid()
            })
        },
        v = function(n) {
            e.update(n).success(function(n) {
                c(n)
            }).error(function() {
                f.roleDic.clearCache();
                h();
                t.refreshGrid()
            })
        },
        y = function(n) {
            if (r.hasRole(n)) {
                var t = s.userOptionKey.discountLimit;
                s.clearUserOption(t)
            }
        },
        p = function(i) {
            i.isTenantAdministrator ? o.info("系统提示", "不能删除公司管理员角色") : o.confirm("删除角色", "您确认要删除角色【" + i.name + "】吗？").then(function() {
                e.destroy(i.id).success(function() {
                    y(i.name);
                    c();
                    t.refreshRemoveGridPage();
                    t.selectedItem = null
                }).error(function(t) {
                    t.name === "EntityAlreadyUsedException" ? o.warn("提示", "该角色下存在用户，不能删除！") : n.error(t)
                })
            })
        },
        w = function() {
            e.exportRolePermissions()
        },
        b = function() {
            var n = t.selectedItem,
                r;
            n && (r = i.open({
                animation: !0,
                backdrop: "static",
                template: "<role-permission-view><\/role-permission-view>",
                controller: "RolePermissionCtrl",
                windowClass: "role-permission-dialog",
                size: "lg",
                resolve: {
                    host: function() {
                        return {
                            role: n
                        }
                    }
                }
            }), r.result.then(function() {}))
        },
        c = function(n) {
            l(n)
        },
        k = function(n) {
            e.copy(n).success(function() {
                l()
            }).error(function() {})
        };
    (function() {
        t.add = a;
        t.update = v;
        t.destroy = p;
        t.close = close;
        t.setRolePermission = b;
        t.copy = k;
        t.exportRoles = w;
        h()
    })()
}]);
tenantModule.controller("RolePermissionCtrl", ["$log", "$scope", "$modalInstance", "dataDicSvc", "roleSvc", "host", "permissionProvider", "aresNotification", "moduleOptionProvider", "officeOptionSvc", "enums", function(n, t, i, r, u, f, e, o, s, h, c) {
    "use strict";
    var l = function() {
            h.getOfficeOption(h.optionKeys.PaymentTypeUpgradeStatus).then(function(n) {
                t.isNewOffice = n == c.PaymentTypeUpgradeStatus.InitUpgraded;
                r.permissionCodedic.load().then(function(n) {
                    n = _.reject(n, {
                        code: "tenantSettings.role"
                    });
                    n = _.reject(n, {
                        isHidden: !0
                    });
                    t.permissionCodes = n;
                    u.getDataPermissions(t.role.id).success(function(i) {
                        t.rolePermissions = i.rolePermission;
                        t.dataPermission = i.dataPermission;
                        var r = i.option ? i.option : {
                            isPersonLevel: !1,
                            isDepartmentLevel: !1,
                            isOnlyMyPatientEditable: !1,
                            isMyPatient: !1,
                            isAppointmentMePatient: !1,
                            isMyDepartmentPatient: !1,
                            isReportDayLimited: !1,
                            reportDayCount: 1,
                            isInventoryCostAllowed: !1,
                            isReportPatientContactAllowed: !1,
                            isReportPatientIdentityCardAllowed: !1
                        };
                        t.option = r;
                        t.permissionCategory = a(n, t.rolePermissions)
                    })
                })
            })
        },
        a = function(n, t) {
            p(n, t);
            var i = _.filter(n, {
                    parentCode: ""
                }),
                r = [];
            return angular.forEach(i, function(t) {
                var i = _.filter(n, {
                    parentCode: t.code
                });
                r.push(i)
            }), angular.forEach(i, function(t) {
                var i = _.filter(n, {
                    parentCode: t.code
                });
                i && i.length > 0 ? (v(i, n), t.items = i, t.spriteCssClass = "folder", t.expanded = !0) : t.spriteCssClass = "html"
            }), i
        },
        v = function(n, t) {
            angular.forEach(n, function(n) {
                var i = _.filter(t, {
                    parentCode: n.code
                });
                i && i.length > 0 ? (y(i, t), n.items = i, n.spriteCssClass = "folder", n.expanded = !1) : n.spriteCssClass = "html"
            })
        },
        y = function(n, t) {
            angular.forEach(n, function(n) {
                var i = _.filter(t, {
                    parentCode: n.code
                });
                i && i.length > 0 ? (n.items = i, n.spriteCssClass = "folder", n.expanded = !1) : n.spriteCssClass = "html"
            })
        },
        p = function(n, i) {
            if (!s.isReferralEnabled()) {
                var r = _.findIndex(n, {
                    code: "referralCenter"
                });
                r > -1 && n.splice(r, 1)
            }
            angular.forEach(n, function(n) {
                var u, f, r;
                t.role.isTenantAdministrator ? n.checked = !0 : (r = _.find(i, {
                    permissionCode: n.code
                }), n.checked = r && r.allow, u = _.find(t.permissionCodes, function(t) {
                    return t.code == n.code && t.code
                }), u && (f = _.find(t.permissionCodes, function(n) {
                    return n.code == u.dependentCode
                }), f && (r = _.find(i, {
                    permissionCode: f.code
                }), n.enabled = r && r.allow ? !0 : !1)))
            })
        },
        w = function() {
            u.getUsers(t.role.id).success(function(n) {
                t.users = n.filter(function(n) {
                    return n.provider ? n.provider.show : !1
                })
            })
        },
        b = function(n) {
            var r, f, s;
            if (t.option.isPersonLevel == !0 && !t.option.isMyPatient && !t.option.isAppointmentMePatient) {
                o.error("当选择个人级时，现有的复选框必须选择至少一个");
                return
            }
            if (!t.option.reportDayCount > 0 && t.option.isReportDayLimited) {
                o.error("报表查看天数必须大于零");
                return
            }
            n.length > 0 || t.dataPermission ? (r = "", t.dataPermission && (r += t.dataPermission.onlyMyPatient ? "1" : "0"), t.option.isMyPatient || t.option.isAppointmentMePatient ? (t.option.isPersonLevel = !0, t.option.isDepartmentLevel = !1) : t.option.isMyDepartmentPatient ? (t.option.isPersonLevel = !1, t.option.isDepartmentLevel = !0) : (t.option.isPersonLevel = !1, t.option.isDepartmentLevel = !1), f = t.option, s = {
                roleId: t.role.id,
                permissions: n,
                dataPermission: r,
                option: f
            }, u.savePermissions(s).success(function() {
                e.refreshPermissions();
                i.close()
            })) : i.close()
        },
        k = function() {
            i.dismiss("cancel")
        };
    (function() {
        t.role = f.role;
        t.allowDatapermission = t.role.name == "牙医" || t.role.name == "牙科助手" || t.role.name == "咨询师";
        t.allowReportpermission = !0;
        t.save = b;
        t.cancel = k;
        t.isAdminOfficeOpen = s.isAdminOfficeOpen();
        l();
        w()
    })()
}]);
tenantModule.controller("SupplyChainConfigCtrl", ["$log", "$scope", "$q", "appNav", "officeSvc", "$timeout", "shortMessageSvc", "aresDialog", "loginContext", "officeOptionSvc", "systemConfigUtil", "systemitemSvc", "$rootScope", "dataDicSvc", "officeUtil", "officeSelectorUtil", "moduleOptionProvider", "tenantSvc", "tenantOptionSvc", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p, w, b, k) {
    "use strict";
    var it = function() {
            var n = i.defer();
            return yt().then(function() {
                ut().then(function() {
                    ft().then(function() {
                        rt().then(function() {
                            b.updateTenantSetting(t.tenantSetting).success(function() {
                                k.refreshTenantOption(k.optionKeys.IsAcrossOfficeInventoryTransferEnabled, t.tenantSetting.isAcrossOfficeInventoryTransferEnabled)
                            });
                            u.updateOfficeSetting(t.officeSetting).success(function() {
                                h.refreshOfficeOption(h.optionKeys.IsInventoryValidityWarnEnabled, t.officeSetting.isInventoryValidityWarnEnabled);
                                h.refreshOfficeOption(h.optionKeys.InventoryValidityWarnDayOffset, t.officeSetting.inventoryValidityWarnDayOffset);
                                h.refreshOfficeOption(h.optionKeys.IsAutoUnpackingEnabled, t.officeSetting.isAutoUnpackingEnabled);
                                h.refreshOfficeOption(h.optionKeys.IsTakeOutWorkflowEnabled, t.officeSetting.isTakeOutWorkflowEnabled);
                                h.refreshOfficeOption(h.optionKeys.IsInventoryTakeWorkflowEnabled, t.officeSetting.isInventoryTakeWorkflowEnabled);
                                h.refreshOfficeOption(h.optionKeys.IsInventoryTakeWarehouseRequired, t.officeSetting.isInventoryTakeWarehouseRequired);
                                h.refreshOfficeOption(h.optionKeys.isInventoryProductSaleEnabled, t.officeSetting.isInventoryProductSaleEnabled);
                                h.refreshOfficeOption(h.optionKeys.IsInventoryCountWarnEnabled, t.officeSetting.isInventoryCountWarnEnabled);
                                h.refreshOfficeOption(h.optionKeys.InventoryCountLowLimit, t.officeSetting.inventoryCountLowLimit);
                                h.refreshOfficeOption(h.optionKeys.DefaultInOrderAction, t.officeSetting.defaultInOrderAction);
                                h.refreshOfficeOption(h.optionKeys.DefaultOutOrderAction, t.officeSetting.defaultOutOrderAction);
                                h.refreshOfficeOption(h.optionKeys.isGroupInventoryEnabled, t.officeSetting.isGroupInventoryEnabled);
                                h.refreshOfficeOption(h.optionKeys.ProcurementCostAllocationRule, t.officeSetting.procurementCostAllocationRule);
                                h.refreshOfficeOption(h.optionKeys.IsProcurementPriceLockEnabled, t.officeSetting.isProcurementPriceLockEnabled);
                                h.refreshOfficeOption(h.optionKeys.InventoryTakeVisibleWarehouse, t.officeSetting.inventoryTakeVisibleWarehouse);
                                h.refreshOfficeOption(h.optionKeys.IsNeedCheckAgreePrice, t.officeSetting.isNeedCheckAgreePrice);
                                h.refreshOfficeOption(h.optionKeys.IsOfficePreferredDealerEnabled, t.officeSetting.isOfficePreferredDealerEnabled);
                                h.refreshOfficeOption(h.optionKeys.ProcurementAssistantConfig, t.officeSetting.procurementAssistantConfig);
                                h.refreshOfficeOption(h.optionKeys.IsShowProductByNickNameEnabled, t.officeSetting.isShowProductByNickNameEnabled);
                                v.officeSettingDic.refresh();
                                v.productCodeOptions.refresh();
                                v.warehouseDic.refresh();
                                v.inventoryConfigOptions.refresh();
                                n.resolve()
                            })
                        })
                    })
                })
            }), n.promise
        },
        rt = function() {
            var n = i.defer();
            return t.currentReceive.ownerType = 2, t.currentReceive.ownerId = s.officeId, t.currentReceive.addressType = 2, u.createInventoryAddress(t.currentReceive).success(function(i) {
                t.currentReceive = i;
                n.resolve()
            }), n.promise
        },
        ut = function() {
            var n = i.defer();
            return angular.forEach(t.inventoryTakePriceByPercent, function(n) {
                switch (n.itemName) {
                    case "领用支持按百分比加价":
                        n.itemValue = t.isInventoryTakePriceByPercentEnabled
                }
            }), l.saveSystemItemList(t.inventoryTakePriceByPercent).success(function(i) {
                t.inventoryTakePriceByPercent = i;
                n.resolve()
            }), n.promise
        },
        ft = function() {
            var n = i.defer();
            return angular.forEach(t.productCodeManage, function(n) {
                switch (n.itemName) {
                    case "启用内部编码":
                        n.itemValue = t.allowInsideCode;
                        break;
                    case "启用厂商编码":
                        n.itemValue = t.allowFirmCode;
                        break;
                    case "启用物品条形码":
                        n.itemValue = t.allowBarCode;
                        break;
                    case "编码唯一性验证":
                        n.itemValue = t.validateCodeUniqueness
                }
            }), l.saveSystemItemList(t.productCodeManage).success(function(i) {
                t.productCodeManage = i;
                n.resolve()
            }), n.promise
        },
        et = function() {
            var n = i.defer();
            return u.getOfficeSetting().success(function(i) {
                t.officeSetting = i;
                s.isGroup || (t.officeSetting.isGroupInventoryEnabled = !0);
                h.getOfficeOption(h.optionKeys.IsConsignmentModeEnabled).then(function(n) {
                    t.isConsignmentModeEnabled = n
                });
                n.resolve()
            }), n.promise
        },
        ot = function() {
            var n = i.defer();
            return b.getTenantSetting().success(function(i) {
                t.tenantSetting = i;
                n.resolve()
            }), n.promise
        },
        st = function() {
            var n = i.defer();
            return v.warehouseDic.loadActive().then(function(i) {
                t.warehouses = i.length > 0 ? i : [];
                n.resolve()
            }), n.promise
        },
        ht = function() {
            var n = i.defer();
            return v.departmentDic.load().then(function(i) {
                i = i || [];
                i.unshift({
                    id: "",
                    itemName: "请选择科室"
                });
                t.departments = i;
                n.resolve()
            }), n.promise
        },
        d = function() {
            l.getSystemItemsByItemType("物品自由项").success(function(n) {
                t.freeTermTypes = n
            })
        },
        ct = function() {
            var n = i.defer();
            return v.currentOfficeWorkProviderIncludeAdminDic.load().then(function(i) {
                t.providers = i;
                n.resolve()
            }), n.promise
        },
        lt = function() {
            l.getSystemItemsByItemType("领用支持按百分比加价").success(function(n) {
                n && n.length > 0 ? (t.inventoryTakePriceByPercent = n, angular.forEach(n, function(n) {
                    switch (n.itemName) {
                        case "领用支持按百分比加价":
                            t.isInventoryTakePriceByPercentEnabled = n.itemValue.toUpperCase() == "TRUE" ? !0 : !1
                    }
                })) : (t.inventoryTakePriceByPercent = [{
                    itemName: "领用支持按百分比加价",
                    itemType: "领用支持按百分比加价",
                    itemValue: !1
                }], t.isInventoryTakePriceByPercentEnabled = !1)
            })
        },
        g = function() {
            l.getSystemItemsByItemType("物品编码管理").success(function(n) {
                t.productCodeManage = [{
                    itemName: "启用内部编码",
                    itemType: "物品编码管理",
                    itemValue: !1
                }, {
                    itemName: "启用厂商编码",
                    itemType: "物品编码管理",
                    itemValue: !1
                }, {
                    itemName: "启用物品条形码",
                    itemType: "物品编码管理",
                    itemValue: !1
                }, {
                    itemName: "编码唯一性验证",
                    itemType: "物品编码管理",
                    itemValue: !1
                }, ];
                t.allowInsideCode = !1;
                t.allowFirmCode = !1;
                t.allowBarCode = !1;
                t.validateCodeUniqueness = !1;
                n && n.length > 0 && angular.forEach(n, function(n) {
                    switch (n.itemName) {
                        case "启用内部编码":
                            t.productCodeManage[0] = n;
                            t.allowInsideCode = n.itemValue ? n.itemValue.toUpperCase() === "TRUE" : !1;
                            break;
                        case "启用厂商编码":
                            t.productCodeManage[1] = n;
                            t.allowFirmCode = n.itemValue ? n.itemValue.toUpperCase() === "TRUE" : !1;
                            break;
                        case "启用物品条形码":
                            t.productCodeManage[2] = n;
                            t.allowBarCode = n.itemValue ? n.itemValue.toUpperCase() === "TRUE" : !1;
                            break;
                        case "编码唯一性验证":
                            t.productCodeManage[3] = n;
                            t.validateCodeUniqueness = n.itemValue ? n.itemValue.toUpperCase() === "TRUE" : !1
                    }
                })
            })
        },
        at = function() {
            var n = i.defer();
            return u.getInventoryAddressByOfficeId(s.officeId).success(function(i) {
                t.currentReceive = i ? i : {
                    province: "",
                    city: "",
                    district: "",
                    content: "",
                    contactName: "",
                    contactPhoneNumber: ""
                };
                n.resolve()
            }), n.promise
        },
        vt = function() {
            var n = i.defer();
            return u.getSelfAndChildOfficesByGroupId(s.officeId, !1).success(function(i) {
                t.officeTreeData = p.setId(i);
                t.officesMap = p.flattenToMap(t.officeTreeData);
                t.regularOfficeList = _.filter(_.values(t.officesMap), function(n) {
                    return !n.isGroup
                });
                n.resolve(!0)
            }), n.promise
        },
        nt = function() {
            var n = i.defer();
            return l.getSystemItemsByItemType("供应链配置").success(function(i) {
                t.supplyChainConfigs = [{
                    itemName: "总部受理诊所采购申请",
                    itemValue: !1,
                    itemType: "供应链配置"
                }, {
                    itemName: "总部角色",
                    itemValue: "purchaser",
                    itemType: "供应链配置"
                }];
                i && i.length > 0 && t.supplyChainConfigs.forEach(function(n, r) {
                    var u = i.find(function(t) {
                        return t.itemName == n.itemName
                    });
                    u && (t.supplyChainConfigs[r] = u);
                    switch (n.itemName) {
                        case "总部受理诊所采购申请":
                            t.isGroupProcurementApplyEnabled = t.supplyChainConfigs[r].itemValue === "True";
                            break;
                        case "总部角色":
                            t.groupProcurementRole = {
                                value: t.supplyChainConfigs[r].itemValue
                            }
                    }
                });
                n.resolve(!0)
            }), n.promise
        },
        yt = function() {
            var n = i.defer();
            return t.supplyChainConfigs.forEach(function(n) {
                switch (n.itemName) {
                    case "总部受理诊所采购申请":
                        n.itemValue = t.isGroupProcurementApplyEnabled;
                        break;
                    case "总部角色":
                        n.itemValue = t.groupProcurementRole ? t.groupProcurementRole.value : ""
                }
            }), l.saveSystemItemList(t.supplyChainConfigs).success(function(i) {
                t.supplyChainConfigs = i;
                n.resolve()
            }), n.promise
        },
        tt = function() {
            t.isGroupProcurementApplyEnabled && t.groupProcurementRole.value === "seller" ? _.each(t.regularOfficeList, function(n) {
                t.officesMap[n.officeId].isSelfProcurementEnabled = !1;
                t.officesMap[n.officeId].isGroupProcurementEnabled = !0;
                t.officesMap[n.officeId].isGroupSettlementEnabled = !0
            }) : u.getGroupProcurementConfigs().success(function(n) {
                _.each(n, function(n) {
                    n.optionKey === "IsSelfProcurementEnabled" && n.optionValue === "1" ? t.officesMap[n.officeId] && !t.officesMap[n.officeId].isGroup && (t.officesMap[n.officeId].isSelfProcurementEnabled = !0) : n.optionKey === "IsGroupProcurementEnabled" && n.optionValue === "1" ? t.officesMap[n.officeId] && !t.officesMap[n.officeId].isGroup && (t.officesMap[n.officeId].isGroupProcurementEnabled = !0) : n.optionKey === "IsGroupSettlementEnabled" && t.officesMap[n.officeId] && !t.officesMap[n.officeId].isGroup && (t.officesMap[n.officeId].isGroupSettlementEnabled = n.optionValue === "1")
                });
                _.each(t.regularOfficeList, function(n) {
                    angular.isUndefined(n.isGroupProcurementEnabled) && angular.isUndefined(n.isSelfProcurementEnabled) && (t.groupProcurementRole.value === "seller" ? (n.isGroupProcurementEnabled = !0, n.isSelfProcurementEnabled = !1) : (n.isGroupProcurementEnabled = !1, n.isSelfProcurementEnabled = !0));
                    angular.isUndefined(n.isGroupSettlementEnabled) && (n.isGroupSettlementEnabled = t.groupProcurementRole.value === "seller")
                })
            })
        },
        pt = function() {
            var r = i.defer(),
                n = [];
            return _.each(t.regularOfficeList, function(t) {
                n.push({
                    optionKey: "IsSelfProcurementEnabled",
                    optionValue: t.isSelfProcurementEnabled ? 1 : 0,
                    officeId: t.officeId
                });
                n.push({
                    optionKey: "IsGroupProcurementEnabled",
                    optionValue: t.isGroupProcurementEnabled ? 1 : 0,
                    officeId: t.officeId
                });
                n.push({
                    optionKey: "IsGroupSettlementEnabled",
                    optionValue: t.isGroupSettlementEnabled ? 1 : 0,
                    officeId: t.officeId
                })
            }), u.updateGroupProcurementConfigs(n).success(function() {
                r.resolve(!0)
            }), r.promise
        };
    (function() {
        t.isGroup = s.isGroup;
        t.isRegularChain = s.isRegularChain;
        y.isRootGroup().then(function(n) {
            t.isRoot = n
        });
        t.isEdit = !1;
        t.saveConfig = it;
        t.getOfficeSetting = et;
        t.getTenantSetting = ot;
        t.getWarehouse = st;
        t.getDepartment = ht;
        t.getInventoryAddressByOfficeId = at;
        t.getFreeTermTypes = d;
        t.getProductCodeManage = g;
        t.saveGroupProcurementConfigs = pt;
        t.getGroupProcurementConfigs = tt;
        t.getSupplyChainConfigs = nt;
        t.getProviders = ct;
        d();
        lt();
        g();
        vt().then(function() {
            nt().then(function() {
                tt();
                f(function() {
                    t.initOfficeTableScrollbar()
                })
            })
        })
    })()
}]);
tenantModule.controller("TenantPermissionConfigCtrl", ["$log", "$scope", "$q", "appNav", "officeSvc", "$timeout", "shortMessageSvc", "aresDialog", "loginContext", "officeOptionSvc", "systemConfigUtil", "systemitemSvc", "$rootScope", "dataDicSvc", "officeUtil", "officeSelectorUtil", "moduleOptionProvider", "tenantSvc", "tenantOptionSvc", "aresNotification", "workflowSvc", "providerSvc", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p, w, b, k, d, g, nt) {
    "use strict";
    var et = function() {
            it();
            t.isEdit = !1
        },
        it = function() {
            var n = i.defer();
            return u.getTenantOptionAndOfficeOptions(["enableOrthdonticModule", "isOtherMembershipEnabled", "isAutoSplitChargeDetailEnabled", "isThirdPartySpeechCallEnabled", "isDiseaseCertificateEnabled", "isPaymentTypeUpgradeEnabled", "isMembershipBalanceShareDisabled", "isHealthBureauDataExportEnabled_Shenzhen", "isProviderFaceRecognitionRequired", ]).then(function(i) {
                t.tenantOption = i.data;
                t.enableOrthdonticModuleOfficeIds = tt(i.data, "EnableOrthdonticModule");
                t.enableDeductionChargeOfficeIds = tt(i.data, "IsDeductionChargeEnabled");
                t.otherMembershipOfficeIds = tt(i.data, "IsOtherMembershipEnabled");
                t.autoSplitOfficeIds = tt(i.data, "IsAutoSplitChargeDetailEnabled");
                t.thirdPartySpeechCallOfficeIds = tt(i.data, "IsThirdPartySpeechCallEnabled");
                t.diseaseCertificateOfficeIds = tt(i.data, "IsDiseaseCertificateEnabled");
                t.enableHealthShenzhenOfficeIds = tt(i.data, "IsHealthBureauDataExportEnabled_Shenzhen");
                t.requireProviderFaceRecognitionOfficeIds = tt(i.data, "IsProviderFaceRecognitionRequired");
                t.isMembershipBalanceShareEnabled = !i.data.isMembershipBalanceShareDisabled;
                t.baiduTextToAudioConfig = i.data.baiduTextToAudioConfig || {};
                n.resolve(!0)
            }), n.promise
        },
        tt = function(n, t) {
            var i = _.filter(n.officeOptions, function(n) {
                return n.optionKey == t && n.optionValue === "1"
            });
            return _.uniq(_.pluck(i, "officeId"))
        },
        ot = function() {
            var r = i.defer(),
                n = {
                    IsUserSecurityEnabled: t.tenantOption.isUserSecurityEnabled,
                    IsDeductionChargeEnabled: t.tenantOption.isDeductionChargeEnabled,
                    IsDeviceMgmtEnabled: t.tenantOption.isDeviceMgmtEnabled,
                    IsPaymentTypeUpgradeEnabled: t.tenantOption.isPaymentTypeUpgradeEnabled,
                    IsMembershipBalanceShareDisabled: !t.isMembershipBalanceShareEnabled,
                    BaiduTextToAudioConfig: t.baiduTextToAudioConfig,
                    officeOptions: []
                };
            return n.officeOptions.push({
                optionKey: "EnableOrthdonticModule",
                optionValue: t.enableOrthdonticModule,
                optionName: "启用正畸功能",
                officeIds: t.enableOrthdonticModuleOfficeIds
            }), n.officeOptions.push({
                optionKey: "IsDeductionChargeEnabled",
                optionName: "是否开启划扣收费",
                optionValue: t.isDeductionChargeEnabled,
                officeIds: t.enableDeductionChargeOfficeIds
            }), n.officeOptions.push({
                optionKey: "IsAutoSplitChargeDetailEnabled",
                optionName: "是否开启使用卡券时项目自动拆分",
                optionValue: t.isAutoSplitChargeDetailEnabled,
                officeIds: t.autoSplitOfficeIds
            }), n.officeOptions.push({
                optionKey: "IsThirdPartySpeechCallEnabled",
                optionName: "是否启动外部叫号",
                optionValue: t.isThirdPartySpeechCallEnabled,
                officeIds: t.thirdPartySpeechCallOfficeIds
            }), n.officeOptions.push({
                optionKey: "IsOtherMembershipEnabled",
                optionName: "是否允许使用他人会员卡",
                optionValue: t.isOtherMembershipEnabled,
                officeIds: t.otherMembershipOfficeIds
            }), n.officeOptions.push({
                optionKey: "IsDiseaseCertificateEnabled",
                optionName: "是否允许打印疾病证明书",
                optionValue: t.IsDiseaseCertificateEnabled,
                officeIds: t.diseaseCertificateOfficeIds
            }), n.officeOptions.push({
                optionKey: "IsProviderFaceRecognitionRequired",
                optionName: "是否登录必须通过人脸识别",
                optionValue: t.isProviderFaceRecognitionRequired,
                officeIds: t.requireProviderFaceRecognitionOfficeIds
            }), n.officeOptions.push({
                optionKey: "PaymentTypeUpgradeStatus",
                optionName: "支付方式升级状态",
                optionValue: t.upgradStatus
            }), u.saveTenantOptionAndOfficeOptions(n).then(function() {
                d.success("保存成功");
                t.isEdit = !1;
                ft();
                k.refreshTenantOption(k.optionKeys.IsPaymentTypeUpgradeEnabled, t.tenantOption.isPaymentTypeUpgradeEnabled);
                r.resolve(!0)
            }), r.promise
        },
        rt = function(n, t) {
            if (n && n.length > 0) {
                var i = [];
                return _(n).each(function(n) {
                    if (n.isGroup || _(t).include(n.officeId)) {
                        var r = angular.copy(n);
                        r.items = rt(n.items, t);
                        i.push(r)
                    }
                }), i
            }
            return null
        },
        ut = function() {
            var n = i.defer();
            return u.getSelfAndChildOfficesByGroupId(-1e3, !0).success(function(i) {
                var r = i[0];
                r && r.officeId == -1e3 && (r.name = "集团总部");
                t.officeTreeData = p.setId(i);
                t.healthShenzhenOfficeTreeData = rt(t.officeTreeData, t.enableHealthShenzhenOfficeIds);
                n.resolve(!0)
            }), n.promise
        },
        ft = function() {
            t.enableOrthdonticModule = !0;
            t.isOtherMembershipEnabled = !0;
            t.isAutoSplitChargeDetailEnabled = !0;
            t.isThirdPartySpeechCallEnabled = !0;
            t.isDeductionChargeEnabled = !0;
            t.IsDiseaseCertificateEnabled = !0;
            t.isProviderFaceRecognitionRequired = !0;
            it().then(function() {
                ut()
            });
            g.getLDAPConfiguration().success(function(n) {
                t.isLdapEnabled = n
            })
        },
        st = function() {
            return t.tenantOption ? t.tenantOption.isPaymentTypeUpgradeEnabled ? !t.isEdit || !t.tenantOption.isPaymentTypeUpgradeCloseEnabled : !t.isEdit : !0
        },
        ht = function(n) {
            nt.editLDAPProvider(t.enableLDAPOfficeIds, n).success(function(n) {
                n && d.success("操作成功!")
            })
        };
    (function() {
        t.saveTenantOptionAndOfficeOptions = ot;
        t.queryOfficeTreePromise = ut;
        t.cancel = et;
        t.isPaymentTypeUpgradeDisabled = st;
        t.officeOnly = !1;
        t.isLdapEnabled = !1;
        t.editLDAP = ht;
        ft()
    })()
}]);
tenantModule.controller("UserEditCtrl", ["$log", "$scope", "$modalInstance", "appNav", "dataDicSvc", "userSvc", "providerSvc", "aresDialog", "host", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    var h = _.isNumber(s.id),
        c = function() {
            h ? f.get(s.id).success(function(n) {
                t.user = n
            }) : t.user = {
                isInactive: !1
            }
        },
        l = function() {
            h ? f.update(t.user).success(function(n) {
                i.close(n)
            }) : f.create(t.user).success(function(n) {
                i.close(n)
            }).error(function(n) {
                n.name === "AccountNotUniqueException" && o.warn("提示", "账号已经存在！")
            })
        },
        a = function() {
            i.dismiss("cancel")
        };
    (function() {
        t.isEdit = h;
        t.save = l;
        t.cancel = a;
        c()
    })()
}]);
tenantModule.controller("UserListCtrl", ["$log", "$scope", "$modal", "appNav", "dataDicSvc", "userSvc", "aresDialog", function(n, t, i, r, u, f, e) {
    "use strict";
    var o = function() {
            f.list().success(function(n) {
                c(n);
                t.users = n
            })
        },
        s = function() {
            o()
        },
        c = function(n) {
            _.forEach(n, function(n) {
                var r = _.map(n.roles, function(n) {
                        return n.name
                    }),
                    u = r.join(","),
                    t, i;
                n.roleStr = u;
                n.isRoot ? (n.name = "公司管理员", n.officeStr = "所有诊所", n.job = "管理员") : (t = _.map(n.loginOffices, function(n) {
                    return n.name
                }), i = t.join(","), n.officeStr = i, n.provider ? (n.name = n.provider.name, n.job = n.provider.job) : n.name = "");
                n.stateStr = n.isInactive ? "禁用" : "在用"
            })
        },
        l = function() {
            h()
        },
        a = function() {
            t.selectedItem.isRoot ? e.info("系统提示", "不能修改公司管理员") : h(t.selectedItem.id)
        },
        h = function(n) {
            var t = i.open({
                animation: !0,
                backdrop: "static",
                template: "<user-edit-view><\/user-edit-view>",
                controller: "UserEditCtrl",
                windowClass: "user-edit-dialog",
                size: "sm",
                resolve: {
                    host: function() {
                        return {
                            id: n
                        }
                    }
                }
            });
            t.result.then(function(n) {
                n && s()
            })
        },
        v = function() {
            t.selectedItem && (t.selectedItem.isRoot ? e.info("系统提示", "不能删除公司管理员") : e.confirm("删除用户", "您确认要删除用户【" + t.selectedItem.name + "】吗？").then(function() {
                f.destroy(t.selectedItem.id).success(function() {
                    s()
                })
            }))
        },
        y = function() {
            var n = i.open({
                animation: !0,
                backdrop: "static",
                template: "<user-password-edit-view><\/user-password-edit-view>",
                controller: "UserPasswordEditCtrl",
                windowClass: "small-dialog",
                size: "sm",
                resolve: {
                    host: function() {
                        return {
                            id: t.selectedItem.id,
                            account: t.selectedItem.account,
                            isAdminEdit: !0
                        }
                    }
                }
            });
            n.result.then(function() {})
        };
    (function() {
        t.selectedItem = null;
        t.add = l;
        t.edit = a;
        t.changePwd = y;
        t.destroy = v;
        o()
    })()
}]);
tenantModule.controller("WorkflowManagementCtrl", ["$log", "$scope", "$q", "appNav", "officeSvc", "$timeout", "shortMessageSvc", "practiceSvc", "aresDialog", "loginContext", "officeOptionSvc", "systemConfigUtil", "patientSvc", "$rootScope", "dataDicSvc", "chargeItemSvc", "membershipSvc", "officeUtil", "tenantOptionSvc", "aresNotification", "systemSettingItemSvc", "enums", "moduleOptionProvider", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p, w, b, k, d, g, nt, tt) {
    "use strict";
    t.havePublicAccount = !1;
    t.havePrivateAccount = !1;
    t.haveWeixinAccount = !1;
    var it = function(n) {
            if (n != "1" && n) {
                t.monthDescription = "下个月";
                var i = moment(Ares.today()).startOf("month").date(n).add(1, "months").add(-1, "days").date();
                t.nextMonthDateStr = i + "日"
            } else t.monthDescription = "本月", t.nextMonthDateStr = "最后一天"
        },
        et = function() {
            if (angular.forEach(t.officeSetting.systemConfigs, function(n) {
                    n.configName == "ApplyCDTCharge" ? n.configValue = t.systemConfigs.applyCDTChargeValue ? "true" : "false" : n.configName == "ApplyRCCharge" ? n.configValue = t.systemConfigs.applyRCChargeValue ? "true" : "false" : n.configName == "AllowSingleDiscount" ? n.configValue = t.systemConfigs.allowSingleDiscountValue ? "true" : "false" : n.configName == "AllowAliPay" ? n.configValue = t.systemConfigs.allowAliPay ? "true" : "false" : n.configName == "EnableAliF2FPay" ? n.configValue = t.systemConfigs.enableAliF2FPay ? "true" : "false" : n.configName == "ApplyDetailCharge" ? n.configValue = t.systemConfigs.applyDetailChargeValue ? "true" : "false" : n.configName == "ApplySimpleCharge" ? n.configValue = t.systemConfigs.applySimpleChargeValue ? "true" : "false" : n.configName == "ApplyDisposalCharge" ? n.configValue = t.systemConfigs.applyDisposalChargeValue ? "true" : "false" : n.configName == "PrintMembershipBalance" ? n.configValue = t.systemConfigs.printMembershipBalance ? "true" : "false" : n.configName == "AllowCopyDisposal" ? n.configValue = t.systemConfigs.allowCopyDisposal ? "true" : "false" : n.configName == "DefaultCharge" ? n.configValue = t.systemConfigs.DefaultCharge : n.configName == "PrintChargeNotes" ? n.configValue = t.systemConfigs.printChargeNotes : n.configName == "IsPayOverdue" ? n.configValue = t.systemConfigs.isPayOverdue ? "true" : "false" : n.configName == "AllowMinDiscount" ? n.configValue = t.systemConfigs.allowMinDiscount ? "true" : "false" : n.configName == "ChargeMinDiscount" ? n.configValue = t.systemConfigs.chargeMinDiscount : n.configName == "ChargeDetailMinDiscount" ? n.configValue = t.systemConfigs.chargeDetailMinDiscount : n.configName == "AllowStatement" ? n.configValue = t.systemConfigs.allowStatement ? "true" : "false" : n.configName == "AllowAllotChargeDetail" ? n.configValue = t.systemConfigs.allowAllotChargeDetail ? "true" : "false" : n.configName == "AllowChargeDeductionManHours" ? n.configValue = t.systemConfigs.allowChargeDeductionManHours ? "true" : "false" : n.configName == "AllowInsuranceCharge" ? n.configValue = t.systemConfigs.allowInsuranceCharge ? "true" : "false" : n.configName == "AllowWeixinBillOrder" ? n.configValue = t.systemConfigs.allowWeixinBillOrder ? "true" : "false" : n.configName == "AllowBorwserChargeItem" ? n.configValue = t.systemConfigs.allowBorwserChargeItem ? "true" : "false" : n.configName == "AllowSetWeixin" ? n.configValue = t.systemConfigs.allowSetWeixin ? "true" : "false" : n.configName == "AllowWeixinPay" ? n.configValue = t.systemConfigs.allowWeixinPay ? "true" : "false" : n.configName === "AllowSealingTime" ? n.configValue = t.systemConfigs.allowSealingTime ? "true" : "false" : n.configName === "CustomSealingTime" ? n.configValue = moment(t.sealingTimePicker).format("HH:mm:ss") : n.configName === "IsEnableGiftCard" ? n.configValue = t.systemConfigs.isEnableGiftCard ? "true" : "false" : n.configName === "IsEnableICCard" ? n.configValue = t.systemConfigs.isEnableICCard ? "true" : "false" : n.configName === "IsEnableWorkflow" ? n.configValue = t.systemConfigs.isEnableWorkflow ? "true" : "false" : n.configName === "AllowShareGiftCertificateInPatientRelations" ? n.configValue = t.systemConfigs.allowShareGiftCertificateInPatientRelations ? "true" : "false" : n.configName === "AdvancePaymentUsingRate" ? n.configValue = t.systemConfigs.advancePaymentUsingRate : n.configName === "IsDefaultDeductionPlan" ? n.configValue = t.systemConfigs.isDefaultDeductionPlan : n.configName === "AllowDeposit" ? n.configValue = t.systemConfigs.allowDeposit : n.configName === "IsEnableFinanceDay" ? n.configValue = t.systemConfigs.isEnableFinanceDay ? "true" : "false" : n.configName === "FinanceDay" ? ((typeof t.systemConfigs.financeDay == "undefined" || t.systemConfigs.financeDay == null) && (t.systemConfigs.financeDay = "1"), n.configValue = t.systemConfigs.financeDay, it(t.systemConfigs.financeDay)) : n.configName === "Pattern4CancellingOrder" ? n.configValue = t.systemConfigs.pattern4CancellingOrder : n.configName === "GroupBuyCertificateConsumeBy" ? n.configValue = t.systemConfigs.groupBuyCertificateConsumeBy : n.configName === "IsStudentDefaultOrderDiscount" ? n.configValue = t.systemConfigs.isStudentDefaultOrderDiscount : n.configName === "StudentDefaultOrderDiscount" ? n.configValue = t.systemConfigs.studentDefaultOrderDiscount : n.configName === "IsRefundReasonEnabled" ? n.configValue = t.systemConfigs.isRefundReasonEnabled : n.configName === "AllowRefundAutoRevertDeduction" ? n.configValue = t.systemConfigs.allowRefundAutoRevertDeduction : n.configName === "DeductionRevertMode" ? n.configValue = t.systemConfigs.deductionRevertMode : n.configName === "IsInPerformanceByAdvanceCharge" ? n.configValue = t.systemConfigs.isInPerformanceByAdvanceCharge : n.configName === "IsChargeItemProviderUnique" ? n.configValue = t.systemConfigs.isChargeItemProviderUnique : n.configName === "ChargeItemProviderRange" ? n.configValue = t.systemConfigs.chargeItemProviderRange : n.configName === "IsMemebershipGiftDefaultEnabled" ? n.configValue = t.systemConfigs.isMemebershipGiftDefaultEnabled : n.configName == "IsOrderRefundEnable" ? n.configValue = t.systemConfigs.isOrderRefundEnable ? "true" : "false" : n.configName == "IsItemRefundEnable" ? n.configValue = t.systemConfigs.isItemRefundEnable ? "true" : "false" : n.configName == "IsPriceRefundEnable" ? n.configValue = t.systemConfigs.isPriceRefundEnable ? "true" : "false" : n.configName === "IsGiftCertDrawFromChargeEnable" ? n.configValue = t.systemConfigs.isGiftCertDrawFromChargeEnable : n.configName === "IsShowChargeSellerEnabled" ? n.configValue = t.systemConfigs.isShowChargeSellerEnabled : n.configName === "IsShowAutoDeductionExecuteSwitchEnabled" ? n.configValue = t.systemConfigs.isShowAutoDeductionExecuteSwitchEnabled : n.configName === "IsOverdueAsIncomeEnabled" && (n.configValue = t.systemConfigs.isOverdueAsIncomeEnabled)
                }), t.editCheckedInTypeCondition == 1 ? (t.officeSetting.firstVisitRule.hasCheckedIn = !1, t.officeSetting.firstVisitRule.hasCompleted = !1) : (t.officeSetting.firstVisitRule.hasCharged = !1, t.officeSetting.firstVisitRule.hasDealt = !1), t.editCheckedInTypeCondition == 1 && !t.officeSetting.firstVisitRule.hasCharged && !t.officeSetting.firstVisitRule.hasDealt || t.editCheckedInTypeCondition == 0 && !t.officeSetting.firstVisitRule.hasCheckedIn && !t.officeSetting.firstVisitRule.hasCompleted) {
                d.error("有效预约条件必须选一个！");
                return
            }
            if (t.officeSetting.autoFollowupRuleChooseMode = t.isAutoFollowupRuleByChargeAmount ? nt.FollowupRuleChooseMode.ByChargeAmount : nt.FollowupRuleChooseMode.ByRulePriority, t.baseDataConfig && (t.officeSetting.baseDataConfig = JSON.stringify(t.baseDataConfig)), u.updateOfficeSetting(t.officeSetting).success(function() {
                    var n, i, r;
                    t.isChangeApp && (n = {
                        AppointmentReminderTemplates: t.appTemplates
                    }, o.updateAppointmentReminderTemplates(n));
                    i = _.union([t.defaultCheckInChargeItemTemplate], t.specialCheckInChargeItemTemplates);
                    r = {
                        Templates: i
                    };
                    p.updateChargeItemCheckInTemplates(r).success(function() {
                        y.chargeItemCheckInTemplateDic.refresh()
                    });
                    t.isDiscountLimitChanged && u.updateOfficeChargeDiscountLimit(t.discountLimitSettings).success(function() {
                        y.discountLimitSettingsDic.refresh()
                    });
                    c.refreshOfficeOption(c.optionKeys.IsCheckInTypeEditable, t.officeSetting.isCheckInTypeEditable);
                    c.refreshOfficeOption(c.optionKeys.FirstVisitRule, t.officeSetting.firstVisitRule);
                    c.refreshOfficeOption(c.optionKeys.ApptTitleColor, t.officeSetting.isApptTileColorEnabled);
                    c.refreshOfficeOption(c.optionKeys.DoctorViewWholeScheduler, t.officeSetting.canDoctorViewWholeScheduler);
                    c.refreshOfficeOption(c.optionKeys.StrictApptWorkflow, t.officeSetting.isStrictApptWorkflowEnabled);
                    c.refreshOfficeOption(c.optionKeys.EnableConsultantDiagnose, t.officeSetting.isEnableConsultantDiagnose);
                    c.refreshOfficeOption(c.optionKeys.AllowApptToConsultant, t.officeSetting.isAllowApptToConsultant);
                    c.refreshOfficeOption(c.optionKeys.IsCheckInWithConsultOpen, t.officeSetting.isCheckInWithConsultOpen);
                    c.refreshOfficeOption(c.optionKeys.IsAppointmentSourceEnabled, t.officeSetting.isAppointmentSourceEnabled);
                    c.refreshOfficeOption(c.optionKeys.IsOnlyWeixinReminder, t.officeSetting.IsOnlyWeixinReminder);
                    c.refreshOfficeOption(c.optionKeys.IsOpenSpeechCall, t.officeSetting.isOpenSpeechCall);
                    c.refreshOfficeOption(c.optionKeys.EnableOpenAppointmentRemark, t.officeSetting.isEnableOpenAppointmentRemark);
                    c.refreshOfficeOption(c.optionKeys.EnableOpenAppointmentCaseNo, t.officeSetting.isEnableOpenAppointmentCaseNo);
                    l.refreshCache(t.officeSetting.systemConfigs);
                    c.refreshOfficeOption(c.optionKeys.CheckInNotifyDoctor, t.officeSetting.isEnableCheckInNotifyDoctor);
                    c.refreshOfficeOption(c.optionKeys.CompleteNotifyFront, t.officeSetting.isEnableCompleteNotifyFront);
                    c.refreshOfficeOption(c.optionKeys.ChargeNotifyFront, t.officeSetting.isEnableChargeNotifyFront);
                    c.refreshOfficeOption(c.optionKeys.ChargeCompleteNotifyDoctor, t.officeSetting.isEnableChargeCompleteNotifyDoctor);
                    c.refreshOfficeOption(c.optionKeys.LeaveNotifyFront, t.officeSetting.isEnableLeaveNotifyFront);
                    c.refreshOfficeOption(c.optionKeys.SpeechCallTimes, t.officeSetting.speechCallTimes);
                    c.refreshOfficeOption(c.optionKeys.SpeechCallMode, t.officeSetting.speechCallMode);
                    c.refreshOfficeOption(c.optionKeys.IsMedicalExamOpen, t.officeSetting.isMedicalExamOpen);
                    c.refreshOfficeOption(c.optionKeys.AllowDeposit, t.officeSetting.allowDeposit);
                    c.refreshOfficeOption(c.optionKeys.IsStudentDefaultOrderDiscount, t.officeSetting.isStudentDefaultOrderDiscount);
                    c.refreshOfficeOption(c.optionKeys.StudentDefaultOrderDiscount, t.officeSetting.studentDefaultOrderDiscount);
                    c.refreshOfficeOption(c.optionKeys.IsStrongStrictApptWorkflowEnabled, t.officeSetting.IsStrongStrictApptWorkflowEnabled);
                    c.refreshOfficeOption(c.optionKeys.IsInPerformanceByAdvanceCharge, t.officeSetting.isInPerformanceByAdvanceCharge);
                    c.refreshOfficeOption(c.optionKeys.IsProviderPerformanceRechargeEnabled, t.officeSetting.isProviderPerformanceRechargeEnabled);
                    c.refreshOfficeOption(c.optionKeys.IsProviderPerformanceWithdrawEnabled, t.officeSetting.isProviderPerformanceWithdrawEnabled);
                    c.refreshOfficeOption(c.optionKeys.IsChargeAllotDeductionFirstEnabled, t.officeSetting.isChargeAllotDeductionFirstEnabled);
                    c.refreshOfficeOption(c.optionKeys.IsGiftCertificateInAdvanceEndabled, t.officeSetting.isGiftCertificateInAdvanceEndabled);
                    c.refreshOfficeOption(c.optionKeys.isChargeOverdueDisabled, t.officeSetting.isChargeOverdueDisabled);
                    c.refreshOfficeOption(c.optionKeys.ChargeOrderPayTimeRule, t.officeSetting.chargeOrderPayTimeRule);
                    c.refreshOfficeOption(c.optionKeys.AutoFollowupRuleChooseMode, t.officeSetting.autoFollowupRuleChooseMode);
                    c.refreshOfficeOption(c.optionKeys.IsSendAdviceWhenAutoFollowupEnabled, t.officeSetting.isSendAdviceWhenAutoFollowupEnabled);
                    c.refreshOfficeOption(c.optionKeys.PreoperativeRemindConfig, t.officeSetting.preoperativeRemindConfig);
                    c.refreshOfficeOption(c.optionKeys.IsGiftCertificateInAdvanceEndabled, t.officeSetting.isGiftCertificateInAdvanceEndabled);
                    c.refreshOfficeOption(c.optionKeys.IsHistoryFinanceDayDeductionEnabled, t.officeSetting.isHistoryFinanceDayDeductionEnabled);
                    c.refreshOfficeOption(c.optionKeys.IsNewMedicalExamEnabled, t.officeSetting.isNewMedicalExamEnabled);
                    c.refreshOfficeOption(c.optionKeys.FinanceDayBuffer, t.officeSetting.financeDayBuffer);
                    c.refreshOfficeOption(c.optionKeys.IsNewPaymentTypeEnabled, t.officeSetting.isNewPaymentTypeEnabled);
                    c.refreshOfficeOption(c.optionKeys.IsMessageNotDisturbDisalbed, t.officeSetting.isMessageNotDisturbDisalbed);
                    c.refreshOfficeOption(c.optionKeys.IsMessageClearAllDisalbed, t.officeSetting.isMessageClearAllDisalbed);
                    c.refreshOfficeOption(c.optionKeys.MessagePostponeConfig, t.officeSetting.messagePostponeConfig);
                    c.refreshOfficeOption(c.optionKeys.IsOverdueDeductionWarningEnabled, t.officeSetting.isOverdueDeductionWarningEnabled);
                    c.refreshOfficeOption(c.optionKeys.IsOverdueDeductionEnabled, t.officeSetting.isOverdueDeductionEnabled);
                    c.refreshOfficeOption(c.optionKeys.IsChargeOverdueDisabled, t.officeSetting.isChargeOverdueDisabled);
                    c.refreshOfficeOption(c.optionKeys.AutoFollowupConfig, t.officeSetting.autoFollowupConfig);
                    c.refreshOfficeOption(c.optionKeys.IsPacsViewerDefaultEnabled, t.officeSetting.isPacsViewerDefaultEnabled);
                    c.refreshOfficeOption(c.optionKeys.IsChargeItemPriceUpdatable, t.officeSetting.isChargeItemPriceUpdatable);
                    c.refreshOfficeOption(c.optionKeys.IsYibaoItemPriceUpdatable, t.officeSetting.isYibaoItemPriceUpdatable);
                    c.refreshOfficeOption(c.optionKeys.IsYibaoChargeDiagnoseRequired, t.officeSetting.isYibaoChargeDiagnoseRequired);
                    c.refreshOfficeOption(c.optionKeys.IsAppointmentConsultAppendable, t.officeSetting.IsAppointmentConsultAppendable);
                    y.officeSettingDic.refresh();
                    y.paymentTypeDic.clearCache()
                }), st(), ot(), t.systemConfigs.allowSetAli || t.systemConfigs.allowSetWeixin || t.officeSetting.isUnipayEnabled) {
                var n = t.onlinePayAccount.unipayAccountData;
                t.onlinePayAccount.unipayAccount = JSON.stringify(n);
                u.updateOnlinePayAccount(t.onlinePayAccount).success(function() {
                    t.saveOver()
                })
            } else t.saveOver()
        },
        ot = function() {
            var n = {
                isPatientProtected: t.speechCallScreen.isPatientProtected,
                screenRefreshInterval: t.speechCallScreen.screenRefreshInterval,
                columnCnt: t.speechCallScreen.columnCnt,
                rowCnt: ""
            };
            g.saveSpeechCallConfig(n).success(function() {
                y.speechCallScreenConfigDic.clearCache()
            })
        },
        st = function() {
            var n = i.defer(),
                r = [];
            return t.chargeItemFreeFields.forEach(function(n) {
                r.push(n)
            }), g.saveChargeItemFreeFields(r).success(function() {
                y.chargeItemFreeFieldDic.clearCache();
                r.some(function(n) {
                    return !n.id
                }) && (y.chargeItemFreeField1ItemDic.clearCache(), y.chargeItemFreeField2ItemDic.clearCache(), y.chargeItemFreeField3ItemDic.clearCache());
                n.resolve()
            }).error(function(t) {
                t.name == "SystemItemNameNotUniqueException" && (d.error("自由项不能重名！"), item.isEmpty = !0, n.reject())
            }), n.promise
        },
        ht = function() {
            var n = nt.BaseDataCategory,
                i = n.ChargeItem;
            y.officeBaseDataOptionDic.load().then(function(n) {
                var r = _.find(n, function(n) {
                    return n.category == i
                });
                t.chargeItemAboutEnabled = r && r.isParentEnabled ? !1 : !0
            })
        },
        ct = function() {
            var n = i.defer();
            return o.getAppointmentReminderTemplates().success(function(i) {
                t.shortMessageTemplates = i;
                t.defaultTemplate = _.find(i, function(n) {
                    return n.isDefault
                });
                var u = _.map(i, function(n) {
                        return n.patientType
                    }),
                    r = _.indexOf(u, "");
                r != -1 && t.shortMessageTemplates.splice(r, 1);
                e.getShortMessageTemplateByCategory("预约").success(function(i) {
                    t.appointmentTemplates = i;
                    o.getItemTypes("patientType").success(function(i) {
                        t.patientTypes = i;
                        n.resolve()
                    }).error(function(t) {
                        n.reject(t)
                    })
                }).error(function(t) {
                    n.reject(t)
                })
            }).error(function(t) {
                n.reject(t)
            }), n.promise
        },
        lt = function(n) {
            var r = i.defer(),
                u, f;
            return n && t.officeSetting.isApptSurveyEnabled ? (u = n, f = {
                long_Url: u
            }, e.checkCanConvetToShortenUrl(f).success(function(n) {
                n ? r.resolve() : r.reject(err)
            }).error(function(n) {
                r.reject(n)
            })) : r.resolve(), r.promise
        },
        at = function() {
            var n = i.defer();
            return y.chargeItemCheckInTemplateDic.load(function(n) {
                return !n.groupId
            }).then(function(i) {
                var r = angular.copy(i),
                    u = _.find(r, function(n) {
                        return n.isDefault
                    });
                t.defaultCheckInChargeItemTemplate = u || {
                    checkInType: "",
                    chargeItems: [],
                    isDefault: !0
                };
                t.specialCheckInChargeItemTemplates = _.without(r, t.defaultCheckInChargeItemTemplate);
                t.defaultCheckInChargeItemTemplate.chargeItemNames = rt(t.defaultCheckInChargeItemTemplate.chargeItems);
                angular.forEach(t.specialCheckInChargeItemTemplates, function(n) {
                    n.chargeItemNames = rt(n.chargeItems)
                });
                o.getItemTypes("就诊类型").success(function(i) {
                    t.checkInTypes = i;
                    n.resolve()
                }).error(function(t) {
                    n.reject(t)
                })
            }).catch(function(t) {
                n.reject(t)
            }), n.promise
        },
        vt = function() {
            var n = i.defer();
            return y.discountLimitSettingsDic.load().then(function(i) {
                if (t.discountLimitSettings = angular.copy(i), !i || i.length == 0) {
                    var r = {
                        id: 0,
                        scope: 1,
                        referenceId: h.officeId,
                        orderLowerLimit: 0,
                        detailLowerLimit: 0,
                        overdueLowerLimit: 0
                    };
                    t.discountLimitSettings = [r]
                }
                y.roleDic.load().then(function(i) {
                    t.roleTypes = i;
                    n.resolve()
                })
            }).catch(function(t) {
                n.reject(t)
            }), n.promise
        },
        ut = function() {
            var n;
            t.monthList = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28"];
            t.fullMonthList = ["0", "1"].concat(t.monthList).map(function(n) {
                return parseInt(n)
            });
            t.shortMessageTemplates = [];
            t.hasAliPayAccount = !1;
            t.hasDianpingGroupBuy = !1;
            w.getDianpingShopInfo().then(function(n) {
                n.data && (t.hasDianpingGroupBuy = !0)
            });
            t.isDeductionChargeEnabled = !1;
            y.officeSettingDic.load().then(function(n) {
                t.isDeductionChargeEnabled = n.isDeductionChargeEnabled
            });
            var r = y.chargeItemFreeFieldDic.load().then(function(n) {
                    t.chargeItemFreeFields = n
                }),
                u = y.speechCallScreenConfigDic.load().then(function(n) {
                    t.speechCallScreen = n
                }),
                f = b.isRootGroup().then(function(n) {
                    t.isRoot = n
                });
            return yt(), bt(), n = [ht(), ct(), at(), vt(), wt(), ft(), pt(), r, u, f], i.all(n).then(function() {
                t.initTimeOut()
            })
        },
        yt = function() {
            t.isAdvanceChargeEnabled = !1;
            c.getOfficeOption(c.optionKeys.PaymentTypeUpgradeStatus).then(function(n) {
                n == nt.PaymentTypeUpgradeStatus.Finished && (t.isAdvanceChargeEnabled = tt.isAdvanceChargeEnabled())
            })
        },
        pt = function() {
            var n = i.defer();
            return y.shortMessageTemplateDic.loadActive().then(function(i) {
                var r = angular.copy(i);
                angular.forEach(r, function(n) {
                    n.name = n.category + " - " + n.name
                });
                t.allShortMessageTemplates = _.sortBy(r, "name");
                n.resolve(!0)
            }), n.promise
        },
        wt = function() {
            var n = i.defer();
            return u.getOfficeSetting().success(function(i) {
                t.officeSetting = i;
                i && (i.firstVisitRule && (t.editCheckedInTypeCondition = i.firstVisitRule.hasCharged || i.firstVisitRule.hasDealt ? 1 : 0), t.isAutoFollowupRuleByChargeAmount = i.autoFollowupRuleChooseMode == nt.FollowupRuleChooseMode.ByChargeAmount, t.baseDataConfig = t.officeSetting.baseDataConfig ? JSON.parse(t.officeSetting.baseDataConfig) : {
                    chargeItemRequired: {
                        procedureCode: !1
                    }
                });
                t.systemConfigs = {};
                var r = t.officeSetting.systemConfigs;
                angular.forEach(t.officeSetting.systemConfigs, function(n) {
                    n.configName == "ApplyCDTCharge" ? t.systemConfigs.applyCDTChargeValue = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "ApplyRCCharge" ? t.systemConfigs.applyRCChargeValue = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "AllowSingleDiscount" ? t.systemConfigs.allowSingleDiscountValue = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "AllowAliPay" ? t.systemConfigs.allowAliPay = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "EnableAliF2FPay" ? t.systemConfigs.enableAliF2FPay = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "ApplyDetailCharge" ? t.systemConfigs.applyDetailChargeValue = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "ApplySimpleCharge" ? t.systemConfigs.applySimpleChargeValue = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "ApplyDisposalCharge" ? t.systemConfigs.applyDisposalChargeValue = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "PrintMembershipBalance" ? t.systemConfigs.printMembershipBalance = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "DefaultCharge" ? t.systemConfigs.DefaultCharge = n.configValue : n.configName == "AllowCopyDisposal" ? t.systemConfigs.allowCopyDisposal = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "AllowSetAli" ? t.systemConfigs.allowSetAli = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "PrintChargeNotes" ? t.systemConfigs.printChargeNotes = n.configValue : n.configName == "IsPayOverdue" ? t.systemConfigs.isPayOverdue = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "AllowNewCharge" ? t.systemConfigs.allowNewCharge = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "AllowMinDiscount" ? t.systemConfigs.allowMinDiscount = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "AllowStatement" ? t.systemConfigs.allowStatement = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "AllowAllotChargeDetail" ? t.systemConfigs.allowAllotChargeDetail = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "AllowChargeDeductionManHours" ? t.systemConfigs.allowChargeDeductionManHours = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "AllowInsuranceCharge" ? t.systemConfigs.allowInsuranceCharge = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "AllowWeixinBillOrder" ? t.systemConfigs.allowWeixinBillOrder = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "AllowBorwserChargeItem" ? t.systemConfigs.allowBorwserChargeItem = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "AllowSetWeixin" ? t.systemConfigs.allowSetWeixin = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "AllowWeixinPay" ? t.systemConfigs.allowWeixinPay = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName === "AllowSealingTime" ? t.systemConfigs.allowSealingTime = n.configValue.toUpperCase() === "TRUE" : n.configName === "CustomSealingTime" ? t.sealingTimePicker = moment(n.configValue, "HH:mm:ss").toDate() : n.configName === "IsEnableGiftCard" ? t.systemConfigs.isEnableGiftCard = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName === "IsEnableICCard" ? t.systemConfigs.isEnableICCard = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName === "IsOpenSpeechCall" ? t.systemConfigs.isOpenSpeechCall = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName === "IsEnableWorkflow" ? t.systemConfigs.isEnableWorkflow = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName === "AllowShareGiftCertificateInPatientRelations" ? t.systemConfigs.allowShareGiftCertificateInPatientRelations = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName === "AdvancePaymentUsingRate" ? t.systemConfigs.advancePaymentUsingRate = n.configValue : n.configName === "IsDefaultDeductionPlan" ? t.systemConfigs.isDefaultDeductionPlan = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName === "AllowDeposit" ? t.systemConfigs.allowDeposit = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName === "Pattern4CancellingOrder" ? t.systemConfigs.pattern4CancellingOrder = n.configValue : n.configName === "IsEnableFinanceDay" ? t.systemConfigs.isEnableFinanceDay = n.configValue.toUpperCase() === "TRUE" : n.configName === "FinanceDay" ? (t.systemConfigs.financeDay = n.configValue, it(n.configValue)) : n.configName === "GroupBuyCertificateConsumeBy" ? t.systemConfigs.groupBuyCertificateConsumeBy = n.configValue : n.configName === "IsStudentDefaultOrderDiscount" ? t.systemConfigs.isStudentDefaultOrderDiscount = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName === "StudentDefaultOrderDiscount" ? t.systemConfigs.studentDefaultOrderDiscount = parseInt(n.configValue) : n.configName === "IsRefundReasonEnabled" ? t.systemConfigs.isRefundReasonEnabled = n.configValue.toUpperCase() == "TRUE" : n.configName === "AllowRefundAutoRevertDeduction" ? t.systemConfigs.allowRefundAutoRevertDeduction = n.configValue.toUpperCase() == "TRUE" : n.configName === "DeductionRevertMode" ? t.systemConfigs.deductionRevertMode = n.configValue : n.configName === "IsInPerformanceByAdvanceCharge" ? t.systemConfigs.isInPerformanceByAdvanceCharge = n.configValue.toUpperCase() == "TRUE" : n.configName === "IsChargeItemProviderUnique" ? t.systemConfigs.isChargeItemProviderUnique = n.configValue.toUpperCase() == "TRUE" : n.configName === "ChargeItemProviderRange" ? t.systemConfigs.chargeItemProviderRange = n.configValue : n.configName === "IsMemebershipGiftDefaultEnabled" ? t.systemConfigs.isMemebershipGiftDefaultEnabled = n.configValue.toUpperCase() == "TRUE" : n.configName == "IsOrderRefundEnable" ? t.systemConfigs.isOrderRefundEnable = n.configValue.toUpperCase() == "TRUE" : n.configName == "IsItemRefundEnable" ? t.systemConfigs.isItemRefundEnable = n.configValue.toUpperCase() == "TRUE" : n.configName == "IsPriceRefundEnable" ? t.systemConfigs.isPriceRefundEnable = n.configValue.toUpperCase() == "TRUE" : n.configName === "IsGiftCertDrawFromChargeEnable" ? t.systemConfigs.isGiftCertDrawFromChargeEnable = n.configValue.toUpperCase() == "TRUE" : n.configName === "IsShowChargeSellerEnabled" ? t.systemConfigs.isShowChargeSellerEnabled = n.configValue.toUpperCase() == "TRUE" : n.configName === "IsShowAutoDeductionExecuteSwitchEnabled" ? t.systemConfigs.isShowAutoDeductionExecuteSwitchEnabled = n.configValue.toUpperCase() == "TRUE" : n.configName === "IsOverdueAsIncomeEnabled" && (t.systemConfigs.isOverdueAsIncomeEnabled = n.configValue.toUpperCase() == "TRUE" ? !0 : !1)
                });
                n.resolve()
            }), n.promise
        },
        bt = function() {
            k.getTenantOption(k.optionKeys.IsPaymentTypeUpgradeEnabled).then(function(n) {
                t.isPaymentTypeUpgradeEnabled = n
            })
        },
        kt = function(n, i) {
            var r = h.apiToken,
                u = h.tokenType;
            i.url = h.apiHost + "/api/v1/OnlinePayAccount/" + t.uploadType + "";
            i.headers = i.headers || {};
            i.headers.Authorization = u + " " + r;
            i.submit();
            $("#pictureUploadPanel").fileupload("disable")
        },
        dt = function(n, i) {
            var r, u;
            if (i.result != null && typeof i.result == "object") {
                r = {};
                for (u in i.result) r[u] = i.result[u];
                r.type = "preview"
            }
            s.warn("提示", "文件上传成功！");
            ft();
            t.progressBarPercentage = "0%";
            $("#pictureUploadPanel").fileupload("enable")
        },
        gt = function() {
            t.progressBarPercentage = "0%";
            s.error("错误", "文件上传失败！");
            $("#pictureUploadPanel").fileupload("enable")
        };
    t.onlinePayAccount = {};
    var ft = function() {
            var n = i.defer();
            return u.getOnlinePayAccount().success(function(i) {
                i ? (i.aliPublicKey ? t.havePublicAccount = !0 : i.aliPublicKey = "暂无数据，请上传！", i.aliPrivateKey ? t.havePrivateAccount = !0 : i.aliPrivateKey = "暂无数据，请上传！", i.weixinKey ? t.haveWeixinAccount = !0 : i.weixinKey = "暂无数据，请上传！", t.onlinePayAccount = i, (i.aliPublicKey || i.weixinKey) && (t.hasAliPayAccount = !0)) : (t.onlinePayAccount.aliPublicKey = "暂无数据，请上传！", t.onlinePayAccount.aliPrivateKey = "暂无数据，请上传！", t.onlinePayAccount.weixinKey = "暂无数据，请上传！");
                n.resolve()
            }), n.promise
        },
        ni = function(n) {
            n == "public" && (t.public = t.public == "查看" ? "隐藏" : "查看");
            n == "private" && (t.private = t.private == "查看" ? "隐藏" : "查看");
            n == "weixinKey" && (t.weixinKey = t.weixinKey == "查看" ? "隐藏" : "查看")
        },
        ti = function(n) {
            var i = n.sender;
            i.value() == null && i.value(0);
            i.value() > 100 && i.value(100);
            t.isDiscountLimitChanged = !0
        },
        ii = function(n) {
            var t = n.sender;
            t.value() == null && t.value(0);
            t.value() > 100 && t.value(100)
        },
        rt = function(n) {
            var t = _.pluck(n, "itemName"),
                i = "";
            return t.length == 0 ? i = "未选择收费项" : (t.length > 3 && (t = t.slice(0, 10), t.push("...")), i = t.join(",")), i
        },
        ri = function() {
            var n = t.officeSetting.paymentTypeUpgradeStatus == 2;
            t.officeSetting.isNewPaymentTypeEnabled && !n && (d.error("请先完成支付方式升级，再启用新支付方式"), t.officeSetting.isNewPaymentTypeEnabled = !1)
        };
    (function() {
        t.public = "查看";
        t.private = "查看";
        t.weixinKey = "查看";
        t.sealingTimePicker;
        t.isEdit = !1;
        t.isChangeApp = !1;
        t.editCheckedInTypeCondition = 0;
        t.isAutoFollowupRuleByChargeAmount = !1;
        t.saveConfig = et;
        t.initFinanceDayInfo = it;
        t.onClickBrowser = ni;
        t.addUpload = kt;
        t.uploadFinished = dt;
        t.uploadFailed = gt;
        t.initData = ut;
        t.isDelunCustomFeatureOpen = tt.isDelunCustomFeatureOpen();
        t.isTenantSpeechCallScreenEnabled = tt.isSpeechCallScreenEnabled();
        ut();
        t.isWxClinic = v.isNewWxEnabled;
        t.onLowDiscountLimitChanged = ti;
        t.onStudentDefaultOrderDiscountChange = ii;
        t.getDisplayNames = rt;
        t.isCheckInChanged = !1;
        t.checkCanConvetToShortenUrl = lt;
        t.switchNewPaymentTypeEnabled = ri;
        t.isProfessional = h.isProfessional
    })()
}]);
tenantModule.controller("OfficeSettingBusinessRuleCtrl", ["$log", "$scope", "$timeout", "$q", "$rootScope", "officeSvc", "shortMessageSvc", "practiceSvc", "loginContext", "officeOptionSvc", "systemConfigUtil", "systemitemSvc", "patientSvc", "dataDicSvc", "chargeItemSvc", "membershipSvc", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p) {
    "use strict";
    var b = function(n) {
            return n ? n.replace(/^\S/, function(n) {
                return n.toLowerCase()
            }) : ""
        },
        w = function(n) {
            var t = _.pluck(n, "itemName"),
                i = "";
            return t.length == 0 ? i = "未选择收费项" : (t.length > 3 && (t = t.slice(0, 10), t.push("...")), i = t.join(",")), i
        },
        k = function() {
            t.isWxClinic = u.isNewWxEnabled;
            t.monthList = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28"]
        },
        d = function() {
            var n = r.defer();
            return v.officeSettingDic.load().then(function(i) {
                t.officeSetting = i;
                var r = {},
                    u = i.systemConfigs;
                u.forEach(function(n) {
                    var i = n.configName,
                        u;
                    switch (i) {
                        case "DefaultCharge":
                            r.DefaultCharge = n.configValue;
                            break;
                        case "PrintChargeNotes":
                            r.printChargeNotes = n.configValue;
                            break;
                        case "CustomSealingTime":
                            t.sealingTimePicker = moment(n.configValue, "HH:mm:ss").toDate();
                            break;
                        case "AdvancePaymentUsingRate":
                            r.advancePaymentUsingRate = n.configValue;
                            break;
                        case "Pattern4CancellingOrder":
                            r.pattern4CancellingOrder = n.configValue;
                            break;
                        case "FinanceDay":
                            r.financeDay = n.configValue;
                            t.monthDescription = n.configValue == "1" ? "本月" : "下个月";
                            t.nextMonthDate = moment(Ares.today()).startOf("month").date(r.financeDay).add(1, "months").add(-1, "days").date();
                            break;
                        case "GroupBuyCertificateConsumeBy":
                            r.groupBuyCertificateConsumeBy = n.configValue;
                            break;
                        case "StudentDefaultOrderDiscount":
                            r.studentDefaultOrderDiscount = parseInt(n.configValue);
                            break;
                        default:
                            u = n.configValue.toUpperCase();
                            r[b(i)] = u === "TRUE"
                    }
                });
                t.systemConfigs = r;
                n.resolve()
            }), n.promise
        },
        g = function() {
            var n = r.defer();
            return f.getOnlinePayAccount().success(function(i) {
                i ? (i.aliPublicKey ? t.havePublicAccount = !0 : i.aliPublicKey = "暂无数据，请上传！", i.aliPrivateKey ? t.havePrivateAccount = !0 : i.aliPrivateKey = "暂无数据，请上传！", i.weixinKey ? t.haveWeixinAccount = !0 : i.weixinKey = "暂无数据，请上传！", t.onlinePayAccount = i) : (t.onlinePayAccount.aliPublicKey = "暂无数据，请上传！", t.onlinePayAccount.aliPrivateKey = "暂无数据，请上传！", t.onlinePayAccount.weixinKey = "暂无数据，请上传！");
                n.resolve()
            }), n.promise
        },
        nt = function() {
            var n = r.defer();
            return o.getAppointmentReminderTemplates().success(function(i) {
                t.shortMessageTemplates = i;
                t.defaultTemplate = _.find(i, function(n) {
                    return n.isDefault
                });
                var u = _.map(i, function(n) {
                        return n.patientType
                    }),
                    r = _.indexOf(u, "");
                r != -1 && t.shortMessageTemplates.splice(r, 1);
                e.getShortMessageTemplateByCategory("预约").success(function(i) {
                    t.appointmentTemplates = i;
                    o.getItemTypes("patientType").success(function(i) {
                        t.patientTypes = i;
                        n.resolve()
                    }).error(function(t) {
                        n.reject(t)
                    })
                }).error(function(t) {
                    n.reject(t)
                })
            }).error(function(t) {
                n.reject(t)
            }), n.promise
        },
        tt = function() {
            var n = r.defer();
            return v.chargeItemCheckInTemplateDic.load().then(function(i) {
                var r = angular.copy(i),
                    u = _.find(r, function(n) {
                        return n.isDefault
                    });
                t.defaultCheckInChargeItemTemplate = u || {
                    checkInType: "",
                    chargeItems: [],
                    isDefault: !0
                };
                t.specialCheckInChargeItemTemplates = _.without(r, t.defaultCheckInChargeItemTemplate);
                t.defaultCheckInChargeItemTemplate.chargeItemNames = w(t.defaultCheckInChargeItemTemplate.chargeItems);
                t.specialCheckInChargeItemTemplates.forEach(function(n) {
                    n.chargeItemNames = w(n.chargeItems)
                });
                o.getItemTypes("就诊类型").success(function(i) {
                    t.checkInTypes = i;
                    n.resolve()
                }).error(function(t) {
                    n.reject(t)
                })
            }).catch(function(t) {
                n.reject(t)
            }), n.promise
        },
        it = function() {
            var n = r.defer();
            return v.discountLimitSettingsDic.load().then(function(i) {
                if (t.discountLimitSettings = angular.copy(i), !i || i.length == 0) {
                    var r = {
                        id: 0,
                        scope: 1,
                        referenceId: s.officeId,
                        orderLowerLimit: 0,
                        detailLowerLimit: 0
                    };
                    t.discountLimitSettings = [r]
                }
                v.roleDic.load().then(function(i) {
                    t.roleTypes = i;
                    n.resolve()
                })
            }).catch(function(t) {
                n.reject(t)
            }), n.promise
        },
        rt = function() {
            var n = r.defer();
            return v.shortMessageTemplateDic.loadActive().then(function(i) {
                var r = angular.copy(i);
                angular.forEach(r, function(n) {
                    n.name = n.category + " - " + n.name
                });
                t.allShortMessageTemplates = _.sortBy(r, "name");
                n.resolve(!0)
            }), n.promise
        },
        ut = function() {
            var n = f.hasAliPayAccount().then(function(n) {
                    t.hasAliPayAccount = n.data
                }),
                i = p.getDianpingShopInfo().then(function(n) {
                    t.hasDianpingGroupBuy = n.data ? !0 : !1
                }),
                u = l.getSystemItemsByItemType("收费项目自由项").then(function(n) {
                    t.chargeItemFreeFields = n.data
                });
            return r.all([n, i, u])
        },
        ft = function() {
            return k(), r.all([d(), g(), nt(), tt(), it(), rt(), ut()])
        };
    (function() {
        t.initData = ft;
        t.parseDisplayNames = w
    })()
}]);
tenantModule.directive("accountAcceptanceDialogView", ["$log", "$timeout", "aresNotification", "sessionCache", "aresDialog", "reportUtil", function(n, t, i, r, u, f) {
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/tenant/dialogs/account-acceptance-dialog/account-acceptance-dialog-view.html",
        link: function(n, r) {
            var u, e, o, l = function(i) {
                    var f = [{
                        name: "请选择",
                        value: 0
                    }, {
                        name: "非常满意",
                        value: 5
                    }, {
                        name: "很满意",
                        value: 4
                    }, {
                        name: "满意",
                        value: 3
                    }, {
                        name: "一般",
                        value: 2
                    }, {
                        name: "不满意",
                        value: 1
                    }];
                    u = r.find("#satisfaction").kendoDropDownList({
                        dataSource: f,
                        dataTextField: "name",
                        dataValueField: "value",
                        template: "#: name # ",
                        valueTemplate: "#: name #",
                        select: function(i) {
                            var r = this;
                            t(function() {
                                n.acceptanceReport.satisfaction = r.dataItem(i.item)[r.options.dataValueField]
                            })
                        }
                    }).data("kendoDropDownList");
                    u.enable(!i);
                    e = r.find("#salesSatisfaction").kendoDropDownList({
                        dataSource: f,
                        dataTextField: "name",
                        dataValueField: "value",
                        template: "#: name # ",
                        valueTemplate: "#: name #",
                        select: function(i) {
                            var r = this;
                            t(function() {
                                n.acceptanceReport.salesSatisfaction = r.dataItem(i.item)[r.options.dataValueField]
                            })
                        }
                    }).data("kendoDropDownList");
                    e.enable(!i);
                    o = r.find("#productSatisfaction").kendoDropDownList({
                        dataSource: f,
                        dataTextField: "name",
                        dataValueField: "value",
                        template: "#: name # ",
                        valueTemplate: "#: name #",
                        select: function(i) {
                            var r = this;
                            t(function() {
                                n.acceptanceReport.productSatisfaction = r.dataItem(i.item)[r.options.dataValueField]
                            })
                        }
                    }).data("kendoDropDownList");
                    o.enable(!i)
                },
                s = function() {
                    u && u.value(n.acceptanceReport.satisfaction);
                    e && e.value(n.acceptanceReport.salesSatisfaction);
                    o && o.value(n.acceptanceReport.productSatisfaction)
                },
                a = function() {
                    var t = n.acceptanceReport;
                    n.steps = 2;
                    n.acceptStep = 1;
                    n.stepsLength = t.steps.length;
                    n.acceptanceReportSteps = t.steps[0];
                    n.setCache()
                },
                v = function() {
                    var i = n.acceptanceReport,
                        t = n.acceptStep,
                        r = n.stepsLength,
                        u = angular.copy(n.acceptanceReportSteps.stepItems);
                    t == "last" ? (n.acceptStep = r, n.acceptanceReportSteps = i.steps[r - 1]) : t > 1 ? (n.acceptStep--, n.acceptanceReportSteps = i.steps[n.acceptStep - 1]) : t == 1 && (n.steps = 1);
                    n.setCache()
                },
                y = function() {
                    var t = n.acceptanceReport,
                        i;
                    n.acceptStep < t.steps.length ? (n.acceptanceReportSteps.complate = !0, i = angular.copy(n.acceptanceReportSteps.stepItems), n.acceptStep++, n.acceptanceReportSteps = t.steps[n.acceptStep - 1]) : (n.acceptanceReportSteps.complate = !0, n.acceptStep = "last");
                    n.setCache()
                },
                p = function(t) {
                    var i = t == 1 ? !1 : !0;
                    n.acceptanceReport.isAccepted = i;
                    n.setAcceptanceReport()
                },
                h = function() {
                    var i = n.acceptanceReport,
                        r = i.trainingStartTime,
                        u = i.trainingEndTime,
                        t;
                    r && u && (t = moment(u).diff(moment(r), "days"), n.period = t >= 0 ? t + "天" : "")
                },
                c = function() {
                    var t, i;
                    if (n.acceptanceReport.id > 0) t = moment(n.acceptanceReport.trainingStartTime).format("YYYY-MM-DD"), i = moment(n.acceptanceReport.trainingEndTime).add(1, "day").format("YYYY-MM-DD"), n.timeSpan = {
                        startDate: t,
                        endDate: i
                    };
                    else {
                        var r = f.getDefaultTimeSpan(),
                            t = moment().format("YYYY-MM-DD"),
                            i = moment().add(1, "day").format("YYYY-MM-DD");
                        n.acceptanceReport.trainingStartTime = t;
                        n.acceptanceReport.trainingEndTime = i;
                        n.timeSpan = {
                            startDate: t,
                            endDate: i
                        }
                    }
                    n.timeSpan.isDisabled = n.officeInfo.isAccepted;
                    h()
                },
                w = function(t) {
                    t = t || n.timeSpan;
                    n.acceptanceReport.trainingStartTime = moment(t.startDate).format("YYYY-MM-DD");
                    n.acceptanceReport.trainingEndTime = moment(t.endDate).add(1, "day").format("YYYY-MM-DD");
                    h()
                };
            (function() {
                n.acceptanceTo = a;
                n.prevStep = v;
                n.nextStep = y;
                n.save = p;
                n.onDateRangeChanged = w;
                var t = n.officeInfo.isAccepted;
                l(t);
                n.getSaasInfo().then(function(r) {
                    r ? (n.getAcceptanceReport().then(function(u) {
                        u ? (t ? (n.acceptanceReport = u, c(), s()) : n.getOfficeConsultants().then(function(t) {
                            if (t) {
                                var i = t.find(n => n.positonName === "口腔销售"),
                                    r = t.find(n => n.positonName === "实施");
                                i && (u.sellerName = i.consultantName, u.sellerPhoneNo = i.phoneNumer);
                                r && (u.csmName = r.consultantName, u.csmPhoneNo = r.phoneNumer)
                            }
                            n.acceptanceReport = u;
                            c();
                            s()
                        }), u.id || (u.trainingStartTime = r.serviceStart)) : i.error("验收报告初始化失败。")
                    }), n.currentOfficeInfo = r) : i.error("BMS未查询到诊所信息。")
                })
            })()
        }
    }
}]);
tenantModule.controller("AccountAcceptanceDialogCtrl", ["$q", "$scope", "$modalInstance", "loginContext", "officeSvc", "host", "sessionCache", "bmsSvc", "aresNotification", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    var c = r.officeId,
        h = e.getCache(e.keys.acceptanceReportCache),
        l = function(n) {
            i.close(n)
        },
        a = function() {
            var t = n.defer();
            return u.getAcceptanceReportTemplateStepData().success(function(n) {
                n ? t.resolve(n) : s.error("当前诊所未配置验收清单模板，请联系管理员。")
            }), t.promise
        },
        v = function() {
            var t = n.defer();
            return a().then(function(n) {
                if (n) {
                    n.forEach(n => {
                        n.stepItems && n.stepItems.forEach(n => {
                            n.isCompleted = !0, n.isNotRequired = !0
                        })
                    });
                    var i = {
                        sellerName: "",
                        sellerPhoneNo: "",
                        csmName: "",
                        csmPhoneNo: "",
                        trainingStartTime: "",
                        trainingCount: 1,
                        isHelpKnown: !0,
                        satisfaction: 5,
                        notes: "",
                        acceptanceTime: "",
                        steps: n
                    };
                    t.resolve(i)
                }
            }), t.promise
        },
        d = function() {
            var i = t.officeInfo.isAccepted,
                n = h.loadObject();
            i || _.isEmpty(n) || (t.acceptanceReport = n)
        },
        y = function() {
            var t = n.defer();
            return u.getAcceptanceReportByOfficeId(c).success(function(n) {
                n ? t.resolve(n) : v().then(function(n) {
                    t.resolve(n)
                })
            }), t.promise
        },
        p = function() {
            u.setAcceptanceReport(t.acceptanceReport).then(function() {
                h.saveObject("");
                t.complated = !0
            })
        },
        w = function() {
            var n = t.acceptanceReport;
            h.saveObject(n)
        },
        b = function() {
            var t = n.defer();
            return o.getConsultants().success(function(n) {
                t.resolve(n)
            }), t.promise
        },
        k = function() {
            var t = n.defer();
            return o.getGetProducts("saas", "企业中心").success(function(n) {
                n && n.length != 0 ? t.resolve(n[0]) : (s.error("BMS未查询到当前诊所信息。"), t.resolve())
            }), t.promise
        };
    (function() {
        t.close = l;
        t.steps = 1;
        t.setAcceptanceReport = p;
        t.officeInfo = f.officeInfo;
        t.getAcceptanceReport = y;
        t.setCache = w;
        t.getOfficeConsultants = b;
        t.getSaasInfo = k
    })()
}]);
tenantModule.directive("groupEditView", ["$log", "$timeout", "appNav", function(n, t) {
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/tenant/dialogs/group-edit-view/group-edit-view.html",
        link: function(n, i) {
            Ares.validateForm(i.find("#mainForm"), {
                name: {
                    required: !0,
                    maxlength: 60
                },
                abbreviation: {
                    required: !0,
                    maxlength: 8
                }
            }, {
                name: {
                    required: "请输入诊所名称",
                    maxlength: "诊所名称不能大于60个字符"
                },
                abbreviation: {
                    required: "请输入诊所简称",
                    maxlength: "诊所简称不能大于8个字符"
                }
            });
            var r = function() {
                i.find("#mainForm").valid() && n.save()
            };
            (function() {
                n.onSave = r
            })();
            t(function() {
                Ares.centerModal(i.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
tenantModule.controller("GroupEditCtrl", ["$log", "$scope", "$modalInstance", "dataDicSvc", "officeSvc", "enums", "host", function(n, t, i, r, u, f, e) {
    "use strict";
    var o = e.viewMode && e.viewMode === f.ViewMode.Edit,
        h = function() {
            o ? u.get(e.id).success(function(n) {
                t.office = n
            }) : t.office = {
                isPatientPublic: !1,
                isInactive: !1,
                parentId: e.id,
                officeType: f.OfficeType.Group,
                bizType: 0,
                bizDataShareOption: 0,
                editionCode: f.BusinessEdition.Ultimate40
            }
        },
        c = function() {
            t.office.bizDataShareOption = t.office.bizType;
            o ? u.update(t.office).success(function(n) {
                s(n)
            }) : u.create(t.office).success(function(n) {
                s(n)
            })
        },
        l = function() {
            i.dismiss("cancel")
        },
        s = function(n) {
            r.officeDic.refreshItem(n);
            i.close(n)
        };
    (function() {
        t.isEdit = o;
        t.save = c;
        t.cancel = l;
        h()
    })()
}]);
tenantModule.directive("chargeDeductionAllocationView", ["$log", "$q", "$timeout", "$modal", "practiceSvc", function(n, t, i) {
    return {
        replace: !0,
        templateUrl: "/app/tenant/dialogs/hand-over-dialog/charge-deduction-allocation-view.html",
        link: function(n, t) {
            var r = null,
                u = function() {
                    t.parents(".modal-dialog").css("width", "576px");
                    i(function() {
                        Ares.centerModal(t.closest(".modal-dialog"))
                    }, 50)
                },
                f = function() {
                    r ? r.dataSource.data(n.orProviders) : r = t.find("#executionDoctorInput").kendoDropDownList({
                        dataSource: n.orProviders,
                        filter: "contains",
                        dataTextField: "name",
                        dataValueField: "id",
                        optionLabel: "执行医生",
                        select: function(t) {
                            n.allocation.providerId = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                };
            (function() {
                u();
                n.initProviders();
                f()
            })()
        }
    }
}]);
tenantModule.controller("ChargeDeductionAllocationCtrl", ["$log", "$q", "$timeout", "$scope", "$modalInstance", "host", "handOverSvc", "multiOfficeDataDic", "loginContext", "aresNotification", function(n, t, i, r, u, f, e, o, s, h) {
    "use strict";
    var c = function() {
            u.dismiss()
        },
        l = function() {
            r.orProviders = _.filter(f.orProviders, function(n) {
                return n.show == !0 && !n.isInactive
            })
        },
        a = function() {
            if (!r.allocation.providerId) {
                h.error("请选择员工！");
                return
            }
            v()
        },
        v = function() {
            e.allocationChargeDeduction(r.allocation).success(function(n) {
                u.close(n)
            })
        };
    (function() {
        r.cancel = c;
        r.save = a;
        r.chargeDeductionCount = f.chargeDeductionCount;
        r.initProviders = l;
        r.allocation = {
            officeId: f.officeId,
            chargeDeductions: f.chargeDeductions
        }
    })()
}]);
tenantModule.directive("patientAllocationView", ["$log", "$q", "$timeout", "$modal", "practiceSvc", function(n, t, i) {
    return {
        replace: !0,
        templateUrl: "/app/tenant/dialogs/hand-over-dialog/patient-allocation-view.html",
        link: function(n, t) {
            var r = null,
                u = function() {
                    r = t.find("#handoverTypeInput").kendoDropDownList({
                        optionLabel: "交接人员类型",
                        dataSource: n.handoverTypeList,
                        dataTextField: "name",
                        dataValueField: "id",
                        select: function(t) {
                            n.handoverType = this.dataItem(t.item)[this.options.dataValueField];
                            n.$apply()
                        }
                    }).data("kendoDropDownList")
                },
                f = function() {},
                e = function() {
                    t.parents(".modal-dialog").css("width", "576px");
                    i(function() {
                        Ares.centerModal(t.closest(".modal-dialog"))
                    }, 50)
                };
            (function() {
                e();
                f();
                u();
                n.initProviders();
                n.$watch("handoverType", function() {
                    n.initProviders().then(function(t) {
                        n.providers = t;
                        n.currentSelectedProvider = null
                    })
                })
            })()
        }
    }
}]);
tenantModule.controller("PatientAllocationCtrl", ["$log", "$q", "$timeout", "$scope", "$modalInstance", "host", "handOverSvc", "multiOfficeDataDic", "loginContext", "aresNotification", "moduleOptionProvider", "practiceSvc", "aresConfirmDialog", "dataDicSvc", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v) {
    "use strict";
    var w = function() {
            u.dismiss()
        },
        y = function(n) {
            return _.filter(n, function(n) {
                return (!!n.show || n.show === null) && !n.isInactive
            })
        },
        p = function() {
            var i = f.officeId,
                n = t.defer();
            return r.handoverType === 0 ? o.loadDic(i, "doctorDic").then(function(t) {
                t = y(t);
                n.resolve(t)
            }) : r.handoverType === 1 ? o.loadDic(i, "consultantDic").then(function(t) {
                t = y(t);
                n.resolve(t)
            }) : r.handoverType === 2 ? o.loadDic(i, "webPhoneConsultantDic").then(function(t) {
                t = y(t);
                n.resolve(t)
            }) : r.handoverType === 3 ? v.aliveAttendantDic.loadActive().then(function(t) {
                t = y(t);
                n.resolve(t)
            }) : r.handoverType === 4 ? v.allProviderDic.loadActive().then(function(t) {
                t = y(t);
                n.resolve(t)
            }) : r.handoverType === 5 ? v.allProviderDic.loadActive().then(function(t) {
                t = y(t);
                n.resolve(t)
            }) : r.handoverType === 6 ? o.loadDic(i, "doctorDic").then(function(t) {
                t = y(t);
                n.resolve(t)
            }) : n.resolve([]), n.promise
        },
        b = function() {
            if (r.handoverType === "" || r.handoverType === null) {
                h.error("请选择员工类型！");
                return
            }
            if (!r.currentSelectedProvider) {
                h.error("请选择员工！");
                return
            }
            a.warn({
                message: "已选择" + r.patientCount + "个患者，该操作无法撤销，请仔细核对交接人员。",
                onConfirm: function() {
                    k()
                },
                onCancel: function() {}
            })
        },
        k = function() {
            var n = angular.copy(r.allocation);
            n.handoverType = r.handoverType;
            n.providerId = r.currentSelectedProvider.id;
            e.allocationPatient(n).success(function(n) {
                u.close(n)
            })
        };
    (function() {
        r.cancel = w;
        r.save = b;
        r.patientCount = f.patientCount;
        r.allocation = {
            patientIds: f.patientIds,
            officeId: f.officeId
        };
        r.initProviders = p;
        p();
        r.handoverTypeList = f.handoverTypes
    })()
}]);
tenantModule.directive("officeEditView", ["$log", "$timeout", "enums", function(n, t) {
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/tenant/dialogs/office-edit-view/office-edit-view.html",
        link: function(n, i) {
            Ares.validateForm(i.find("#mainForm"), {
                name: {
                    required: !0,
                    maxlength: 60
                },
                abbreviation: {
                    required: !0,
                    maxlength: 8
                },
                officePhoneNumber: {
                    required: !0,
                    maxlength: 40
                },
                address: {
                    required: !0,
                    maxlength: 255
                },
                code: {
                    maxlength: 60
                },
                contactName: "required",
                contactPhoneNumber: "required",
                businessEdition: "required"
            }, {
                name: {
                    required: "请输入诊所名称",
                    maxlength: "诊所名称不能大于60个字符"
                },
                abbreviation: {
                    required: "请输入诊所简称",
                    maxlength: "诊所简称不能大于8个字符"
                },
                officePhoneNumber: {
                    required: "请输入诊所号码",
                    maxlength: "诊所号码不能大于40个字符"
                },
                address: {
                    required: "请输入诊所地址",
                    maxlength: "诊所名称不能大于255个字符"
                },
                contactName: "请输入联系人",
                contactPhoneNumber: "请输入联系电话",
                businessEdition: "请选择版本",
                code: {
                    maxlength: "诊所编码不能大于60个字符"
                }
            });
            var u = function() {
                    i.find("#mainForm").valid() && (n.isVersionSelectable && r && (n.office.editionCode = r.value()), n.save())
                },
                r = null,
                f = function(t) {
                    var u = _(n.editions).filter(function(n) {
                        return n.isEnabled || n.editionCode == t.editionCode
                    });
                    r = i.find("#businessEdition").kendoDropDownList({
                        dataSource: u,
                        dataValueField: "code",
                        dataTextField: "name",
                        optionLabel: "请选择版本",
                        value: t.editionCode
                    }).data("kendoDropDownList")
                },
                e = function() {
                    n.init().then(function(n) {
                        t(function() {
                            f(n)
                        })
                    })
                };
            (function() {
                n.save2 = u;
                e()
            })();
            t(function() {
                Ares.centerModal(i.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
tenantModule.controller("OfficeEditCtrl", ["$log", "$scope", "$modalInstance", "appNav", "dataDicSvc", "officeSvc", "host", "enums", "aresDialog", "$q", function(n, t, i, r, u, f, e, o, s, h) {
    "use strict";
    var c = e.viewMode && e.viewMode === o.ViewMode.Edit,
        a = function() {
            var n = h.defer();
            return t.isOfficeTypeVisible = e.isOfficeTypeVisible, t.isVersionSelectable = e.isVersionSelectable, u.businessEditionDic.load().then(function(i) {
                if (t.editions = i, c) f.get(e.id).success(function(i) {
                    t.office = i;
                    n.resolve(i)
                }).error(function(t) {
                    n.reject(t)
                });
                else {
                    var r = e.isOfficeTypeVisible || !t.$root.isRegularChain ? 0 : 1;
                    t.office = {
                        isPatientPublic: !1,
                        isInactive: !1,
                        parentId: e.id,
                        officeType: o.OfficeType.Office,
                        bizType: r,
                        bizDataShareOption: r == 0 ? 0 : 1
                    };
                    n.resolve(t.office)
                }
            }), n.promise
        },
        v = function() {
            t.office.bizDataShareOption = t.office.bizType;
            c ? f.update(t.office).success(function(n) {
                l(n)
            }) : f.create(t.office).success(function(n) {
                l(n)
            })
        },
        y = function() {
            i.dismiss("cancel")
        },
        l = function(n) {
            u.officeDic.refreshItem(n);
            i.close(n)
        };
    (function() {
        t.isEdit = c;
        t.save = v;
        t.cancel = y;
        t.init = a
    })()
}]);
tenantModule.directive("officeTransferDialogView", ["$log", "$timeout", "$modal", "appNav", "officeSvc", "enums", "moduleOptionProvider", function(n, t, i, r, u, f) {
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/tenant/dialogs/office-transfer-dialog-view/office-transfer-dialog-view.html",
        link: function(n, r) {
            var u = function() {
                    var t = i.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<office-group-dialog-view><\/office-group-dialog-view>",
                        controller: "OfficeGroupDialogCtrl",
                        windowClass: "office-group-dialog",
                        resolve: {
                            host: function() {
                                return {
                                    selectMode: "multi2",
                                    selectScope: f.OfficeTreeSelectScope.All,
                                    rootGroupId: -1e3,
                                    isDescendantDataOpen: !0,
                                    selectedIds: n.transferringOfficeIds.join(","),
                                    selectedNames: n.transferringOfficeNames.join(","),
                                    maxShowCount: 3e3
                                }
                            }
                        }
                    });
                    t.result.then(function(t) {
                        t && (n.transferringOfficeNames = t.selectedNames ? t.selectedNames.split(",") : [], n.transferringOfficeIds = t.selectedIds ? _.map(t.selectedIds.split(","), function(n) {
                            return parseInt(n)
                        }) : [])
                    })
                },
                e = function() {
                    var t = i.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<office-group-dialog-view><\/office-group-dialog-view>",
                        controller: "OfficeGroupDialogCtrl",
                        windowClass: "office-group-dialog",
                        resolve: {
                            host: function() {
                                return {
                                    selectMode: "single",
                                    selectScope: f.OfficeTreeSelectScope.Group,
                                    rootGroupId: n.rootGroupId,
                                    selectedIds: n.transferTargetId,
                                    selectedNames: n.transferTargetName,
                                    isDescendantDataOpen: !0
                                }
                            }
                        }
                    });
                    t.result.then(function(t) {
                        t && (n.transferTargetName = t.selectedNames, n.transferTargetId = parseInt(t.selectedIds))
                    })
                };
            (function() {
                n.selectTranferringOffices = u;
                n.selectTransferTarget = e;
                n.transferringOfficeNames = [];
                n.transferringOfficeIds = [];
                n.transferTargetName = "";
                n.transferTargetId = ""
            })();
            t(function() {
                Ares.centerModal(r.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
tenantModule.controller("OfficeTransferDialogCtrl", ["$log", "$scope", "$modalInstance", "appNav", "dataDicSvc", "officeSvc", "host", "enums", "aresDialog", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    var l = function() {},
        h = function() {
            i.dismiss("cancel")
        },
        c = function() {
            if (!t.transferringOfficeIds || t.transferringOfficeIds.length == 0) {
                s.warning("提示", "请选择需要迁移的节点。");
                return
            }
            if (!t.transferTargetId) {
                s.warning("提示", "请选择迁入节点。");
                return
            }
            var n = {
                transferringOfficeIds: t.transferringOfficeIds,
                transferTargetId: t.transferTargetId
            };
            i.close(n)
        };
    (function() {
        t.rootGroupId = e.rootGroupId;
        t.cancel = h;
        t.ok = c
    })()
}]);
tenantModule.directive("partnerAccountDialogView", ["$log", "$timeout", "aresNotification", "aresDialog", "$modal", function(n, t, i, r, u) {
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/tenant/dialogs/partner-account-dialog/partner-account-dialog-view.html",
        link: function(n) {
            var t = function() {
                var t = u.open({
                    animation: !0,
                    backdrop: "static",
                    template: "<partner-channel-dialog-view><\/partner-channel-dialog-view>",
                    controller: "PartnerChannelDialogCtrl",
                    size: "md",
                    resolve: {
                        host: function() {
                            return {
                                partnerData: n.partnerData
                            }
                        }
                    }
                });
                t.result.then(function() {
                    n.searchPartner()
                })
            };
            (function() {
                n.partnerDialog = t
            })()
        }
    }
}]);
tenantModule.controller("PartnerAccountDialogCtrl", ["$log", "$scope", "$modalInstance", "host", "partnerSvc", "aresNotification", "$timeout", function(n, t, i, r, u, f) {
    "use strict";
    var o = function() {
            i.dismiss("cancel")
        },
        s = function() {
            if (t.form.password !== t.confirmPassword) {
                f.error("密码不一致");
                return
            }
            if (!t.partner) {
                f.error("请选择渠道");
                return
            }
            if (t.form.partnerId = t.partner.id, r.type === 1) t.form.isEidtPassword = t.isEidtPassword, u.updateAccount(t.form).then(function(n) {
                n && i.close()
            });
            else {
                if (!t.form.partnerId) {
                    f.error("请选择渠道");
                    return
                }
                u.addAccount(t.form).then(function(n) {
                    n && i.close()
                })
            }
        },
        e = function() {
            return u.searchPartner().then(function(n) {
                return t.partnerData = n.data, !0
            })
        },
        h = function() {
            r.type === 1 && (t.form.id = t.item.id, t.form.name = t.item.name, t.form.mobile = t.item.mobile, t.form.account = t.item.account, t.form.password = t.item.password, t.form.partnerId = t.item.partnerId, t.partner = {
                id: t.item.partnerId,
                name: t.item.partnerName
            }, t.confirmPassword = t.item.password, t.isEidtPassword = t.item.isEidtPassword);
            console.log("partnerId", t.item.partnerId)
        },
        c = function() {
            t.isEidtPassword ? (t.form.password = "", t.confirmPassword = "") : (t.form.password = t.item.password, t.confirmPassword = t.item.password)
        };
    (function() {
        console.log("host", r.item);
        t.cancel = o;
        t.title = r.title;
        t.type = r.type;
        t.item = r.item || [];
        t.save = s;
        t.form = {};
        t.searchPartner = e;
        t.change = c;
        e().then(function() {
            h()
        })
    })()
}]);
tenantModule.directive("partnerChannelDialogView", ["$log", "$timeout", "aresNotification", "aresDialog", "$modal", function() {
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/tenant/dialogs/partner-channel-dialog/partner-channel-dialog-view.html",
        link: function() {
            (function() {})()
        }
    }
}]);
tenantModule.controller("PartnerChannelDialogCtrl", ["$log", "$scope", "$modalInstance", "host", "partnerSvc", "aresNotification", function(n, t, i, r, u) {
    "use strict";
    var e = function() {
            i.close()
        },
        o = function() {
            t.partnerData.push({
                id: "",
                name: "",
                isNew: !0
            })
        },
        s = function(n) {
            n.isNew = !0;
            n.isEdit = !0
        },
        h = function(n, i) {
            u.deletePartner(i).then(function(i) {
                i && t.partnerData.splice(n, 1)
            })
        },
        c = function(n) {
            var t = {
                id: n.id,
                name: n.name
            };
            n.isEdit ? u.updatePartner(t).then(function(t) {
                t && (n.isNew = !1)
            }) : u.addPartner(t).then(function(t) {
                t && (n.isNew = !1, f())
            })
        },
        f = function() {
            u.searchPartner().then(function(n) {
                t.partnerData = n.data
            })
        },
        l = function(n, i) {
            i.isEdit ? i.isNew = !1 : t.partnerData.splice(n, 1)
        };
    (function() {
        t.close = e;
        t.cancel = l;
        t.addPartner = o;
        t.editPartner = s;
        t.deletePartner = h;
        t.save = c;
        t.title = "编辑渠道";
        f()
    })()
}]);
tenantModule.directive("todayWorkConfigView", ["$log", "$timeout", "appNav", "enums", function(n, t, i, r) {
    var u = r.RoleDashboardType;
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/tenant/dialogs/today-work-config-view/today-work-config-view.html",
        link: function(n, t) {
            var e = [{
                    text: "前台",
                    value: u.Receptionist
                }, {
                    text: "医生",
                    value: u.Doctor
                }, {
                    text: "咨询师",
                    value: u.Consultant
                }, {
                    text: "网电咨询师",
                    value: u.OnlineConsultant
                }],
                r = t.find("#todaywork").kendoDropDownList({
                    dataSource: e,
                    dataTextField: "text",
                    dataValueField: "value",
                    enable: n.roleName != "前台",
                    change: function() {
                        var t = this.value();
                        n.onWorkTypeSelected(t);
                        f();
                        i()
                    }
                }).data("kendoDropDownList"),
                o = function() {
                    r && r.value(n.currentDashboardType)
                },
                f = function() {
                    n.$watch("$viewContentLoaded", function() {
                        t.find("#dashboardConfigContainer .todayworkConfig").on("change", function() {
                            var r = t.find(this)[0],
                                u = r.checked,
                                f = r.value;
                            n.onDashboardConfigChanged(f, u);
                            i()
                        });
                        t.find("#checkAll").on("change", function() {
                            var i = this;
                            i.checked ? (t.find(".todayworkConfig").prop("checked", "checked"), n.selectAll()) : (t.find(".todayworkConfig").removeAttr("checked"), n.unselectAll())
                        });
                        i()
                    })
                },
                i = function() {
                    var i = n.currentTypeConfig.filter(function(n) {
                        return n.value.toString().toLowerCase() == "false"
                    });
                    i && i.length > 0 ? t.find("#checkAll").removeAttr("checked") : t.find("#checkAll").prop("checked", "checked")
                },
                s = function() {
                    angular.forEach(n.frontDashboardBlocks, function(t) {
                        t.value = n.checkboxState.isAllSelectedDashboardBlock
                    })
                },
                h = function() {
                    var t = _.find(n.frontDashboardBlocks, {
                        value: !1
                    });
                    n.checkboxState.isAllSelectedDashboardBlock = t ? !1 : !0
                };
            (function() {
                n.setDropdownlistValue = o;
                n.bindConfigChangeEvent = f;
                n.isDashboardBlockAllSelected = !0;
                n.onSelectedAll = s;
                n.onSelectedItem = h
            })()
        }
    }
}]);
tenantModule.controller("TodayWorkConfigCtrl", ["$log", "$scope", "$timeout", "$modalInstance", "appNav", "$q", "dataDicSvc", "officeSvc", "roleSvc", "aresDialog", "role", "enums", function(n, t, i, r, u, f, e, o, s, h, c, l) {
    "use strict";
    var a = l.RoleDashboardType,
        v = [],
        y = [],
        w = [{
            name: "newRegister",
            description: "新增患者",
            value: !0
        }, {
            name: "newAppointment",
            description: "新增预约",
            value: !0
        }, {
            name: "todayVisit",
            description: "今日就诊",
            value: !0
        }, {
            name: "totalCharge",
            description: "实收金额",
            value: !0
        }, {
            name: "followupCount",
            description: "随访人次",
            value: !0
        }, {
            name: "smsCount",
            description: "短信",
            value: !0
        }, ];
    v[a.Receptionist] = [{
        name: "todayCheck",
        description: "今日就诊",
        value: "true"
    }, {
        name: "todayAccount",
        description: "今日对账",
        value: "true"
    }, {
        name: "uncharge",
        description: "待收费",
        value: "true"
    }, {
        name: "charged",
        description: "已收费",
        value: "true"
    }, {
        name: "followup",
        description: "今日随访",
        value: "true"
    }, {
        name: "unconfirmAppt",
        description: "明日预约",
        value: "true"
    }, {
        name: "cancelAppt",
        description: "预约已取消",
        value: "true"
    }, {
        name: "pendingAppt",
        description: "待定预约",
        value: "true"
    }, {
        name: "brith",
        description: "生日提醒",
        value: "true"
    }, {
        name: "appointApply",
        description: "网络预约",
        value: "true"
    }, {
        name: "expirationRemind",
        description: "有效期预警",
        value: "true"
    }, {
        name: "todayRevisit",
        description: "今日回访",
        value: "false"
    }, ];
    v[a.Doctor] = [{
        name: "todayCheck",
        description: "今日就诊",
        value: "true"
    }, {
        name: "followup",
        description: "今日随访",
        value: "true"
    }];
    v[a.Consultant] = [{
        name: "todayCheck",
        description: "今日就诊",
        value: "true"
    }, {
        name: "followup",
        description: "今日随访",
        value: "true"
    }];
    v[a.OnlineConsultant] = [{
        name: "todayCheck",
        description: "今日预约",
        value: "true"
    }, {
        name: "todayOnlineConsult",
        description: "今日咨询",
        value: "true"
    }, {
        name: "todayRevisit",
        description: "今日回访",
        value: "true"
    }];
    var b = function() {
            var n = f.defer();
            return s.getDashboardConfig(c.roleId).success(function(t) {
                t ? n.resolve(t.configData) : n.resolve(null)
            }), n.promise
        },
        p = function(n) {
            i(function() {
                t.currentType = n;
                t.currentTypeConfig = y[n];
                t.bindConfigChangeEvent()
            })
        },
        k = function(n, i) {
            var r = t.currentTypeConfig.filter(function(t) {
                return t.name == n
            });
            r && r.length > 0 && (r[0].value = i)
        },
        d = function() {
            for (var n = 0; n < t.currentTypeConfig.length; n++) t.currentTypeConfig[n].value = "true"
        },
        g = function() {
            for (var n = 0; n < t.currentTypeConfig.length; n++) t.currentTypeConfig[n].value = "false"
        },
        nt = function() {
            r.dismiss("cancel")
        },
        tt = function() {
            var n = {};
            n.roleId = c.roleId;
            n.type = 1;
            n.configData = [{
                type: t.currentType,
                items: y[t.currentType],
                blocks: t.currentType == a.Receptionist ? t.frontDashboardBlocks : null
            }];
            s.updateDashboardConfig(n);
            r.dismiss("cancel")
        },
        it = function() {
            b().then(function(n) {
                var r, h, i, o;
                if (y = v, n && n.length > 0)
                    for (r = 0; r < n.length; r++) {
                        var f = n[r],
                            e = f.type,
                            u = f.items,
                            s = _.find(u, function(n) {
                                return n.name === "todayRevisit"
                            });
                        !s && u && u.push({
                            name: "todayRevisit",
                            description: "今日回访",
                            value: "false"
                        });
                        h = f.blocks;
                        y[e] = u;
                        t.currentDashboardType = e
                    }
                i = _.find(n, {
                    type: a.Receptionist
                });
                i && i.blocks && (angular.forEach(i.blocks, function(n) {
                    n.value = n.value.toLowerCase() == "true"
                }), t.frontDashboardBlocks = i.blocks, o = _.find(t.frontDashboardBlocks, {
                    value: !1
                }), t.checkboxState.isAllSelectedDashboardBlock = o ? !1 : !0);
                p(t.currentDashboardType);
                t.setDropdownlistValue()
            })
        };
    (function() {
        t.currentDashboardType = a.Receptionist;
        t.onWorkTypeSelected = p;
        t.roleName = c.roleName;
        t.roleId = c.roleId;
        t.cancel = nt;
        t.save = tt;
        t.onDashboardConfigChanged = k;
        t.selectAll = d;
        t.unselectAll = g;
        t.frontDashboardBlocks = w;
        t.checkboxState = {
            isAllSelectedDashboardBlock: !0
        };
        it()
    })()
}]);
tenantModule.factory("tenantUtil", ["$log", "$q", "$modal", "chargeSvc", "patientSvc", "aresDialog", "aresModalShelf", "paySvc", "deductionSvc", "membershipSvc", "aresNotification", function(n, t, i, r, u, f, e) {
    "use strict";
    var o = function(n) {
        var t = e.open({
            template: "<account-acceptance-dialog-view><\/account-acceptance-dialog-view>",
            controller: "AccountAcceptanceDialogCtrl",
            title: "实施验收清单",
            titleIconClass: "iconfont icon-yanshou",
            resolve: {
                host: function() {
                    return {
                        officeInfo: n
                    }
                }
            },
            needActive: !0
        });
        return t.result
    };
    return {
        openAcceptanceReportDialog: o
    }
}]);
tenantModule.directive("accountAcceptanceView", ["$log", "$timeout", "$state", "officeSvc", "aresModalShelf", function(n, t, i, r, u) {
    return {
        templateUrl: "/app/tenant/views/account-acceptance-view.html",
        controller: "AccountAcceptanceCtrl",
        link: function(n) {
            var t = function() {
                var t = u.open({
                    template: "<account-acceptance-dialog-view><\/account-acceptance-dialog-view>",
                    controller: "AccountAcceptanceDialogCtrl",
                    title: "实施验收清单",
                    titleIconClass: "iconfont icon-yanshou",
                    resolve: {
                        host: function() {
                            return {
                                officeInfo: n.officeInfo
                            }
                        }
                    },
                    needActive: !0
                });
                t.result.then(function(t) {
                    t && n.browserOffice()
                })
            };
            (function() {
                n.acceptanceDialog = t
            })()
        }
    }
}]);
imagingModule.directive("aliTurnOn", ["$log", "$timeout", "$state", "officeSvc", "aresDialog", function(n, t, i, r, u) {
    return {
        templateUrl: "/app/tenant/views/ali-turn-on.html",
        link: function(n) {
            var t = function() {
                    r.checkAliServiceStatus().success(function(n) {
                        n != null && (n.alipayAccountStatus != null && n.alipayAccountStatus.toLowerCase() == "true" && $("#step1").attr("src", "../Content/imgs/alipay/confirm.png"), n.facetofacePayStatus != null && n.facetofacePayStatus.toLowerCase() == "true" && $("#step2").attr("src", "../Content/imgs/alipay/confirm.png"), n.scanCodePayStatus != null && n.scanCodePayStatus.toLowerCase() == "true" && $("#step3").attr("src", "../Content/imgs/alipay/confirm.png"), n.spentByStagePayStatus != null && n.spentByStagePayStatus.toLowerCase() == "true" && $("#step4").attr("src", "../Content/imgs/alipay/confirm.png"), n.serviceWindowStatus != null && n.serviceWindowStatus.toLowerCase() == "true" && $("#step5").attr("src", "../Content/imgs/alipay/confirm.png"))
                    })
                },
                i = function(n) {
                    r.askForAliServiceStatus(n).success(function() {
                        u.info("支付宝服务申请", "您的申请已提交，稍后领健客服将与您取得联系，请保持电话畅通。")
                    })
                };
            (function() {
                n.askForopen = i;
                t()
            })()
        }
    }
}]);
tenantModule.directive("aliUploadView", ["$log", "$timeout", "$state", "officeSvc", function() {
    return {
        restrict: "A",
        scope: {
            add: "&",
            send: "&",
            start: "&",
            stop: "&",
            fail: "&",
            destroy: "&",
            done: "&",
            uploadprogress: "&"
        },
        link: function(n, t) {
            function i(n, t) {
                var i = {
                    dataType: "json",
                    type: "POST",
                    sequentialUploads: !0,
                    autoUpload: !0,
                    multipart: !1
                };
                n.add && (i.add = function(t, i) {
                    n.$apply(function() {
                        n.add({
                            e: t,
                            data: i
                        })
                    })
                });
                n.fail && (i.fail = function(t, i) {
                    n.$apply(function() {
                        n.fail({
                            e: t,
                            data: i
                        })
                    })
                });
                n.done && (i.done = function(t, i) {
                    n.$apply(function() {
                        n.done({
                            e: t,
                            data: i
                        })
                    })
                });
                n.uploadprogress && (i.progress = function(t, i) {
                    n.$apply(function() {
                        n.uploadprogress({
                            e: t,
                            data: i
                        })
                    })
                });
                t.fileupload(i)
            }
            var r = function() {
                    n.$parent.$parent.uploadType = "public";
                    $("#payKeyUploadPanel").click()
                },
                u = function() {
                    $("#rsaPublicKey").on("click", r)
                },
                f = function() {
                    n.$parent.$parent.uploadType = "private";
                    $("#payKeyUploadPanel").click()
                },
                e = function() {
                    $("#rsaPrivateKey").on("click", f)
                };
            (function() {
                u();
                e()
            })(i(n, t))
        }
    }
}]);
var practice;
(function() {
    "use strict";
    var n = function() {
            function n(n, t, i, r) {
                var u = this;
                this.$scope = n;
                this.hebePortal = t;
                this.host = i;
                this.$modalInstance = r;
                n.init = function() {
                    u.hebePortal.registerOnce("ares.hebeModal.imReady", function(n, t) {
                        u.uniqId = t;
                        console.log("uniqId", t);
                        u.hebePortal.post("hebe.hebeModal.config", {
                            modalName: "doctorCertificate",
                            data: {
                                providerId: u.host.providerId
                            },
                            uniqId: u.uniqId
                        })
                    });
                    u.listenOnceForCloseMessage()
                }
            }
            return n.prototype.listenOnceForCloseMessage = function() {
                var n = this;
                this.hebePortal.registerOnce("ares.hebeModal.close", function(t, i) {
                    if (i !== n.uniqId) {
                        n.listenOnceForCloseMessage();
                        return
                    }
                    console.log("close data", t);
                    n.$modalInstance.close(t)
                })
            }, n.$inject = ["$scope", "hebePortal", "host", "$modalInstance"], n
        }(),
        t = function() {
            function n() {
                this.restrict = "E";
                this.replace = !0;
                this.template = '\n            <div style="width: 100%; height: 100%;">\n                <ares-new-home-view target-route="modalEntry"><\/ares-new-home-view>\n            <\/div>\n        ';
                this.link = function(n) {
                    n.init()
                }
            }
            return n.$inject = [], n
        }();
    practiceModule.controller("Ares3ProviderCertificateEditModalCtrl", Ares.tsController(n));
    practiceModule.directive("ares3ProviderCertificateEditModalView", Ares.tsDirective(t))
})(practice || (practice = {}));
practiceModule.directive("baseDataConfigView", ["$log", "$timeout", "$window", "$q", "dataDicSvc", "loginContext", "permissionProvider", "practiceSvc", "gridOptionUtil", "kendoUtil", function(n, t) {
    "use strict";
    return {
        templateUrl: "/app/tenant/views/base-data-config-view.html",
        controller: "BaseDataConfigCtrl",
        link: function(n) {
            var i = function() {
                    n.saveConfig();
                    n.isEdit = !1
                },
                r = function() {
                    n.isEdit = !n.isEdit
                },
                u = function() {
                    n.getConfig().then(function() {
                        t(function() {
                            n.isEdit = !1
                        })
                    })
                };
            (function() {
                n.save = i;
                n.editConfig = r;
                n.cancel = u
            })()
        }
    }
}]);
var dentalLabConfig;
(function() {
    "use strict";
    var n = function() {
        function n(n, t) {
            this.$timeout = n;
            this.$window = t;
            this.restrict = "E";
            this.templateUrl = "/app/tenant/views/dental-lab-config-view.html";
            this.controller = "DentalLabConfigCtrl";
            this.link = function(n, t) {
                var i = function() {
                        n.isEdit = !1;
                        n.getOfficeSetting().then(function() {
                            r()
                        })
                    },
                    r = function() {
                        var r = t.find(".dental-lab-order-status"),
                            i;
                        r.find("input").prop("checked", !1);
                        _.each(n.dentalLabOrderStatusList, function(n) {
                            r.find("#dentalLabOrderStatus" + n).prop("checked", !0)
                        });
                        i = t.find(".dental-lab-order-required-fields");
                        i.find("input").prop("checked", !1);
                        _.each(n.dentalLabOrderRequiredFields, function(n) {
                            i.find("#required-field-" + n).prop("checked", !0)
                        })
                    },
                    u = function() {
                        n.isEdit = !n.isEdit
                    },
                    f = function() {
                        n.isEdit = !1;
                        i()
                    },
                    e = function() {
                        n.dentalLabOrderStatusList = _.map(t.find(".dental-lab-order-status").find("input[type=checkbox]:checked"), function(n) {
                            return parseInt(angular.element(n).attr("data-value"))
                        });
                        n.dentalLabOrderRequiredFields = _.map(t.find(".dental-lab-order-required-fields").find("input[type=checkbox]:checked"), function(n) {
                            return parseInt(angular.element(n).attr("data-value"))
                        });
                        n.saveOfficeSetting().then(function() {
                            i()
                        })
                    };
                (function() {
                    n.beginEditConfig = u;
                    n.cancelEditConfig = f;
                    n.saveConfig = e;
                    i()
                })()
            }
        }
        return n.$inject = ["$timeout", "$window"], n
    }();
    tenantModule.directive("dentalLabConfigView", Ares.tsDirective(n))
})(dentalLabConfig || (dentalLabConfig = {}));
var dentalLabConfig;
(function() {
    var n = function() {
        function n(n, t, i) {
            this.$scope = n;
            this.$q = t;
            this.officeOptionSvc = i
        }
        return n.prototype.getOfficeSetting = function() {
            var n = this,
                t = n.$q.defer();
            return n.officeOptionSvc.getOfficeOptions([n.officeOptionSvc.optionKeys.DentalLabOrderStatusList, n.officeOptionSvc.optionKeys.DentalLabOrderRequiredFields]).then(function(i) {
                n.$scope.dentalLabOrderStatusList = i[0];
                n.$scope.dentalLabOrderRequiredFields = i[1];
                t.resolve(!0)
            }), t.promise
        }, n.prototype.saveOfficeSetting = function() {
            var n = this,
                t = n.$q.defer(),
                i = [{
                    optionKey: n.officeOptionSvc.optionKeys.DentalLabOrderStatusList,
                    optionValue: JSON.stringify(n.$scope.dentalLabOrderStatusList)
                }, {
                    optionKey: n.officeOptionSvc.optionKeys.DentalLabOrderRequiredFields,
                    optionValue: JSON.stringify(n.$scope.dentalLabOrderRequiredFields)
                }];
            return n.officeOptionSvc.setOfficeOptions(i).then(function() {
                n.officeOptionSvc.refreshOfficeOption(n.officeOptionSvc.optionKeys.DentalLabOrderStatusList);
                n.officeOptionSvc.refreshOfficeOption(n.officeOptionSvc.optionKeys.DentalLabOrderRequiredFields);
                t.resolve(!0)
            }), t.promise
        }, n.$inject = ["$scope", "$q", "officeOptionSvc"], n
    }();
    tenantModule.controller("DentalLabConfigCtrl", Ares.tsController(n))
})(dentalLabConfig || (dentalLabConfig = {}));
practiceModule.directive("freeFieldConfigView", ["$log", "$timeout", "$window", "$q", "dataDicSvc", "loginContext", "permissionProvider", "practiceSvc", "gridOptionUtil", "kendoUtil", function() {
    "use strict";
    return {
        templateUrl: "/app/tenant/views/free-field-config-view.html",
        controller: "FreeFieldConfigCtrl",
        link: function(n) {
            var t = function() {};
            (function() {
                n.infoType = "个人信息";
                t()
            })()
        }
    }
}]);
patientModule.directive("healthInsuranceConfigView", ["$q", "$timeout", "$modal", "$state", "healthInsuranceSvc", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/tenant/views/health-insurance-config-view.html",
        scope: {
            patientId: "="
        },
        link: function(t, i) {
            var r = function() {
                    var t = n.defer();
                    return u.getServiceConfig().then(function(n) {
                        var i = n.data;
                        t.resolve(i)
                    }), t.promise
                },
                f = function() {
                    r().then(function(n) {
                        return e(n)
                    }).then(function(n) {
                        var t = {
                            containerId: "healthInsuranceConfigContainer",
                            processId: null,
                            apiServer: n.baseUrl,
                            url: "/insurance/front/insurance-configuration",
                            token: n.accessToken
                        };
                        InSurance(t);
                        o()
                    })
                },
                e = function(t) {
                    var i = n.defer();
                    return Ares.Loader.loadJs(t.baseUrl + "/plugin.js", function() {
                        i.resolve(t)
                    }), i.promise
                },
                o = function() {
                    var n = i.find("#healthInsuranceConfigContainer iframe");
                    n && n.height(480)
                };
            (function() {
                f()
            })()
        }
    }
}]);
tenantModule.directive("membershipCardNumberConfigView", ["commonRuleUtil", "aresNotification", function(n, t) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/membership-card-number-config-view.html",
        controller: "MembershipCardNumberConfigCtrl",
        link: function(i, r) {
            var f = function() {
                    r.find('[data-toggle="tooltip"]').tooltip({
                        template: '<div class="tooltip tooltip-info" role="tooltip"><div class="tooltip-arrow"><\/div><div class="tooltip-inner"><\/div><\/div>',
                        html: !0
                    })
                },
                e = function() {
                    i.viewState = {
                        isPrefixChecked: !!i.rule.prefix,
                        isDatePartChecked: !!i.rule.dateFormat,
                        originPrefix: i.rule.prefix,
                        originDateFormat: i.rule.dateFormat
                    };
                    u()
                },
                o = function() {
                    i.viewState.isPrefixChecked ? i.rule.prefix = i.viewState.originPrefix : (i.viewState.originPrefix = i.rule.prefix, i.rule.prefix = null);
                    i.viewState.isDatePartChecked ? i.rule.dateFormat = i.viewState.originDateFormat : (i.viewState.originDateFormat = i.rule.dateFormat, i.rule.dateFormat = null);
                    u()
                },
                s = function() {
                    i.viewState.originPrefix = i.rule.prefix;
                    u()
                },
                h = function(n) {
                    i.rule.dateFormat = n;
                    i.viewState.originDateFormat = n;
                    u()
                },
                u = function() {
                    var n = "",
                        r, t, u;
                    if (i.viewState.isPrefixChecked && i.rule.prefix && (n += i.rule.prefix + " "), i.viewState.isDatePartChecked && i.rule.dateFormat && (n += moment(new Date).format(i.rule.dateFormat.toUpperCase()) + " "), i.rule.seqNumberDigits > 0) {
                        for (r = 0; r < i.rule.seqNumberDigits - 1; r++) n += "0";
                        n += "1"
                    }
                    i.rule.initialValue && (t = i.rule.initialValue.toString().length, t > 0 && (u = n.length, u >= t && (n = n.substring(0, u - t), n = n + i.rule.initialValue)));
                    i.viewState.previewCode = n
                },
                c = function() {
                    if (i.rule.initialValue) {
                        var n = 99999999;
                        i.rule.seqNumberDigits && (n = Math.pow(10, i.rule.seqNumberDigits) - 1);
                        i.rule.initialValue < 1 ? i.rule.initialValue = 1 : i.rule.initialValue > n && (i.rule.initialValue = n, t.error("当前最大起始值为：" + n));
                        u()
                    }
                },
                l = function() {
                    var r = n.validate(i.rule);
                    r ? t.error(r) : i.saveConfig().then(function() {
                        i.editable = !1;
                        t.success("保存成功")
                    }, function() {
                        t.success("保存失败")
                    })
                };
            (function() {
                i.editable = !1;
                i.resetViewState = o;
                i.onPrefixChanged = s;
                i.setDateFormat = h;
                i.generatePreviewCode = u;
                i.onInitialValueChanged = c;
                i.onSave = l;
                i.initConfigData().then(function() {
                    f();
                    e()
                })
            })()
        }
    }
}]);
tenantModule.directive("officeAppointmentRequiredView", ["$log", "$timeout", "$state", "appNav", "aresDialog", function(n, t) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/office-appointment-required-view.html",
        controller: "officeAppointmentRequiredCtrl",
        link: function(n, i) {
            var r = function() {
                    n.saveConfig();
                    n.isEdit = !1
                },
                u = function() {
                    n.isEdit = !n.isEdit
                },
                f = function() {
                    n.initData().then(function() {
                        t(function() {
                            n.isEdit = !1
                        })
                    })
                },
                e = function() {
                    i.find(".apptItem").on("change", function() {
                        var t = i.find(this)[0],
                            r = t.checked,
                            u = t.value;
                        n.onApptItemConfigChanged(u, r)
                    })
                };
            (function() {
                n.editConfig = u;
                n.save = r;
                n.cancel = f;
                setTimeout(function() {
                    e()
                }, 800)
            })()
        }
    }
}]);
var tenant;
(function() {
    "use strict";
    var n = function() {
        function n() {
            this.restrict = "E";
            this.replace = !0;
            this.template = '\n            <div class="office-calling-config-view" style="width: 100%; height: calc(100vh - 145px);">\n                <ares-new-home-view target-route="officeSettings.callingConfig"><\/ares-new-home-view>\n            <\/div>\n        '
        }
        return n.$inject = [], n
    }();
    tenantModule.directive("officeCallingConfigView", Ares.tsDirective(n))
})(tenant || (tenant = {}));
tenantModule.directive("officeChargeRequiredView", ["$log", "$timeout", "$state", "appNav", "aresDialog", "aresNotification", function(n, t, i, r, u, f) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/office-charge-required-view.html",
        controller: "officeChargeRequiredCtrl",
        link: function(n, t) {
            var e = function(t, f) {
                    n.onChargeTypeSelect(f);
                    r.setDataSource(n.groupRequiredFiledList);
                    i.setDataSource(n.requiredFiledList);
                    i.value(n.commonChargeRequired);
                    r.value(n.commonChargeGroupRequired);
                    u();
                    n.isEdit = !1;
                    n.courrentIndex = t
                },
                i = t.find("#required").kendoMultiSelect({
                    dataSource: n.requiredFiledList,
                    change: function() {
                        o()
                    }
                }).data("kendoMultiSelect"),
                r = t.find("#groupRequired").kendoMultiSelect({
                    dataSource: n.groupRequiredFiledList,
                    change: function() {
                        s()
                    }
                }).data("kendoMultiSelect"),
                o = function() {
                    var t = i.value();
                    n.resetGroupRequiredFiledList(t);
                    r.setDataSource(n.groupRequiredFiledList)
                },
                s = function() {
                    var t = r.value();
                    n.resetRequiredFieldList(t);
                    i.setDataSource(n.requiredFiledList)
                },
                h = function() {
                    n.isEdit = !0;
                    a()
                },
                c = function() {
                    var e = i.value(),
                        t = r.value();
                    if (t.length == 1) {
                        f.error("组合必填条件不能只包含一项");
                        return
                    }
                    n.save(e, t, n.currentDeduction);
                    n.isEdit = !1;
                    u()
                },
                l = function() {
                    n.onChargeTypeSelect(n.currentSelectedType);
                    i.value(n.commonChargeRequired);
                    r.value(n.commonChargeGroupRequired);
                    r.setDataSource(n.groupRequiredFiledList);
                    i.setDataSource(n.requiredFiledList);
                    n.isEdit = !1;
                    u()
                },
                u = function() {
                    i.enable(!1);
                    r.enable(!1)
                },
                a = function() {
                    i.enable(!0);
                    r.enable(!0)
                },
                v = function() {
                    n.isEdit && (n.currentDeduction = !n.currentDeduction)
                };
            (function() {
                u();
                n.isEdit = !1;
                n.editConfig = h;
                n.saveConfigs = c;
                n.cancel = l;
                n.onChargeTypeSelectHandle = e;
                n.onSwitchClick = v;
                n.initData().then(function() {
                    e(n.courrentIndex, n.currentSelectedType)
                })
            })()
        }
    }
}]);
tenantModule.directive("officeCheckInRequiredView", ["$log", "$timeout", "$state", "appNav", "aresDialog", function(n, t) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/office-check-in-required-view.html",
        controller: "OfficeCheckInRequiredCtrl",
        link: function(n, i) {
            var r = function() {
                    n.saveConfig();
                    n.isEdit = !1
                },
                u = function() {
                    n.isEdit = !n.isEdit
                },
                f = function() {
                    n.initData().then(function() {
                        t(function() {
                            n.isEdit = !1
                        })
                    })
                },
                e = function() {
                    i.find(".checkInItem").on("change", function() {
                        var t = i.find(this)[0],
                            r = t.checked,
                            u = t.value;
                        n.onCheckInItemConfigChanged(u, r)
                    })
                };
            (function() {
                n.editConfig = u;
                n.save = r;
                n.cancel = f;
                setTimeout(function() {
                    e()
                }, 800)
            })()
        }
    }
}]);
var tenant;
(function() {
    "use strict";
    var n = function() {
        function n() {
            this.restrict = "E";
            this.replace = !0;
            this.template = '\n            <div class="office-check-in-setting-view" style="width: 100%; height: calc(100vh - 145px);">\n                <ares-new-home-view target-route="officeSettings.checkInSetting"><\/ares-new-home-view>\n            <\/div>\n        '
        }
        return n.$inject = [], n
    }();
    tenantModule.directive("officeCheckInSettingView", Ares.tsDirective(n))
})(tenant || (tenant = {}));
tenantModule.directive("officeHomeView", ["$log", "$timeout", "$state", "$location", "$q", "appNav", "permissionProvider", "moduleOptionProvider", "loginContext", "officeUtil", "systemConfigSvc", "officeOptionSvc", function(n, t, i, r, u, f, e, o, s, h, c, l) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/office-home-view.html",
        link: function(n) {
            var t = function(t, i, r, u) {
                var e = [];
                i && e.push(new f.TabItem("officeSettings.accountAcceptance", "账户验收", "glyphicon glyphicon-home", "setting.accountAcceptance"));
                e.push(new f.TabItem("officeSettings.info", "当前诊所信息", "glyphicon glyphicon-home", "setting.officeInfo", ["officeSettings.edit"]));
                e.push(new f.TabItem("officeSettings.workflow", "业务规则配置", "glyphicon glyphicon-cog", "setting.office&settings.rule"));
                s.isRoot && e.push(new f.TabItem("officeSettings.permissionConfig", "权限配置", "glyphicon glyphicon-cog", null));
                e.push(new f.TabItem("officeSettings.officeList", "连锁门诊管理", "glyphicon glyphicon-th-list", "tenantSettings.office"));
                e.push(new f.TabItem("officeSettings.patientRequired", "新建患者及必填信息配置", "glyphicon glyphicon-th-list", "setting.office&settings.newPatientInfo"));
                e.push(new f.TabItem("officeSettings.apptRequired", "新建预约必填信息配置", "glyphicon glyphicon-th-list", "setting.office&settings.appointmentInfo"));
                e.push(new f.TabItem("officeSettings.checkInRequired", "挂号必填信息配置", "glyphicon glyphicon-th-list", "setting.office&settings.checkInInfo"));
                e.push(new f.TabItem("officeSettings.chargeRequired", "收费单必填信息配置", "glyphicon glyphicon-th-list", "setting.office&settings.chargeInfo"));
                e.push(new f.TabItem("officeSettings.todaywork", "今日工作配置", "glyphicon glyphicon-cog", "setting.office&settings.todayWork"));
                e.push(new f.TabItem("officeSettings.invoice", "诊所发票信息", "icon-notebook", "setting.invoice"));
                o.isNewInventoryOpen() && (s.isGroup && t || !s.isGroup || s.isGroup && !s.isRegularChain) && e.push(new f.TabItem("officeSettings.supplyChain", "进销存配置", "glyphicon glyphicon-cog", "setting.office&settings.supplychain"));
                e.push(new f.TabItem("officeSettings.freeFieldConfig", "自由项配置", "glyphicon glyphicon-cog", "setting.office&settings.freeField"));
                e.push(new f.TabItem("officeSettings.baseDataConfig", "基础数据配置", "glyphicon glyphicon-cog", "setting.office&settings.baseData"));
                e.push(new f.TabItem("officeSettings.onlineConsultCreateRequired", "网电新建患者及必填信息配置", "glyphicon glyphicon-th-list", "setting.office&settings.onlineConsultCreateInfo"));
                u && e.push(new f.TabItem("officeSettings.healthInsuranceConfig", "商保配置", "glyphicon glyphicon-th-list", "setting.office&settings.healthInsuranceConfig"));
                e.push(new f.TabItem("officeSettings.membershipCardNumConfig", "会员卡号设置", "glyphicon glyphicon-cog", "setting.membershipCardNum"));
                e.push(new f.TabItem("officeSettings.callingConfig", "叫号配置", "glyphicon glyphicon-cog", "setting.office&setting.calling"));
                e.push(new f.TabItem("officeSettings.checkInSetting", "挂号配置", "glyphicon glyphicon-cog", "setting.office&settings.rule"));
                o.isNewDentalLabEnabled() && e.push(new f.TabItem("officeSettings.dentalLabSetting", "技加工配置", "glyphicon glyphicon-cog", "patientOutProcess.config"));
                n.states = e
            };
            (function() {
                u.all([h.isRootGroup(), c.getIsLcCrmEnabled(), c.isPrivateCloud(), l.getOfficeOption(l.optionKeys.IsShangbaoEnabled)]).then(function(n) {
                    t(n[0], n[1], n[2], n[3])
                })
            })()
        }
    }
}]);
practiceModule.directive("officeInfoEditView", ["$log", "$timeout", "aresDialog", "mapUtil", "baiduAreaSvc", "$q", function(n, t, i, r, u, f) {
    "use strict";
    return {
        templateUrl: "/app/tenant/views/office-info-edit-view.html",
        controller: "OfficeInfoEditCtrl",
        link: function(n, e) {
            var l = function() {
                    Ares.validateForm(e.find("#mainForm"), {
                        name: {
                            required: !0,
                            maxlength: 60
                        },
                        abbreviation: {
                            required: !0,
                            maxlength: 8
                        },
                        phoneNumber: {
                            required: !0,
                            maxlength: 40
                        },
                        address: {
                            required: !0,
                            maxlength: 255
                        },
                        website: {
                            maxlength: 60
                        },
                        code: {
                            maxlength: 60
                        }
                    }, {
                        name: {
                            required: "请输入诊所名称",
                            maxlength: "诊所名称不能大于60个字符"
                        },
                        abbreviation: {
                            required: "请输入诊所简称",
                            maxlength: "诊所简称不能大于8个字符"
                        },
                        phoneNumber: {
                            required: "请输入诊所号码",
                            maxlength: "诊所号码不能大于40个字符"
                        },
                        address: {
                            required: "请输入诊所地址",
                            maxlength: "诊所名称不能大于255个字符"
                        },
                        website: {
                            maxlength: "诊所网址不能大于60个字符"
                        },
                        code: {
                            maxlength: "诊所编码不能大于60个字符"
                        }
                    })
                },
                a = function() {
                    var t = /^\d{1,2}:\d\d$/,
                        s = e.find("#openTime").val(),
                        h = e.find("#closeTime").val(),
                        u = e.find("#province").val(),
                        f = e.find("#city").val(),
                        o = e.find("#district").val();
                    if (!t.test(s)) {
                        i.info("信息", "营业时间格式不正确！");
                        return
                    }
                    if (!t.test(h)) {
                        i.info("信息", "营业时间格式不正确！");
                        return
                    }
                    if (u && u.length == 0) {
                        i.info("信息", "请选择省份！");
                        return
                    }
                    if (f && f.length == 0) {
                        i.info("信息", "请选择城市！");
                        return
                    }
                    if (o && o.length == 0) {
                        i.info("信息", "请选择区或县！");
                        return
                    }
                    var c = e.find("#openTime").data("kendoTimePicker"),
                        l = e.find("#closeTime").data("kendoTimePicker"),
                        a = "2016-01-01 " + moment(c.value()).format("HH:mm"),
                        v = "2016-01-01 " + moment(l.value()).format("HH:mm"),
                        y = new Date(a),
                        p = new Date(v);
                    if (y >= p) {
                        i.info("信息", "营业开始时间必须早于结束时间！");
                        return
                    }
                    e.find("#mainForm").valid() && (n.currentOffice.officeLocaltion && r.keys.locationName && (n.currentOffice.officeLocaltion.lng = r.keys.lng, n.currentOffice.officeLocaltion.lat = r.keys.lat, n.currentOffice.officeLocaltion.location = r.keys.locationName), n.saveOffice(n.currentOffice))
                },
                v = function() {
                    var i = moment("2016-01-01 " + n.currentOffice.openTime).toDate(),
                        t;
                    moment(i).isValid() || (i = moment("2016-01-01 09:00").toDate());
                    t = moment("2016-01-01 " + n.currentOffice.closeTime).toDate();
                    moment(t).isValid() || (t = moment("2016-01-01 18:00").toDate());
                    e.find("#openTime").kendoTimePicker({
                        interval: 30,
                        value: i
                    });
                    e.find("#closeTime").kendoTimePicker({
                        interval: 30,
                        value: t
                    })
                },
                s = function(t, i) {
                    var r = f.defer();
                    return n.criteria = {
                        areaCode: t,
                        areaType: i
                    }, u.getSubBaiduAreas(n.criteria).success(function(n) {
                        r.resolve(n)
                    }).error(function(n) {
                        r.reject(n)
                    }), r.promise
                },
                o = function(n, t, i) {
                    var r = e.find(n),
                        u = r.kendoDropDownList({
                            dataSource: t,
                            optionLabel: "请选择",
                            dataTextField: "areaName",
                            dataValueField: "areaName",
                            value: i,
                            select: function(n) {
                                i = this.dataItem(n.item)[this.options.dataValueField] || null
                            }
                        }).data("kendoDropDownList")
                },
                h = function(n, t) {
                    var r = 1,
                        i = _.filter(n, {
                            areaName: t
                        });
                    return i && i.length > 0 && (r = i[0].areaCode), r
                },
                y = function() {
                    n.currentOffice && s(1, 1).then(function(i) {
                        var r, u, f;
                        if (n.currentProvinces = i, o("#province", n.currentProvinces, n.currentOffice.province), c("#province", "#city", n.currentProvinces), r = n.currentOffice.province, r == "北京市" || r == "天津市" || r == "上海市" || r == "重庆市" || r == "澳门特别行政区" || r == "香港特别行政区") {
                            n.currentCitys = [{
                                areaName: r
                            }];
                            n.currentDistricts = [];
                            o("#city", n.currentCitys, n.currentOffice.city);
                            u = h(n.currentProvinces, r);
                            (n.currentOffice.district || n.currentOffice.city && !n.currentOffice.district) && t(s(u, 3).then(function(t) {
                                n.currentDistricts = t;
                                o("#district", n.currentDistricts, n.currentOffice.district)
                            }), 200);
                            return
                        }
                        n.currentOffice.province && (f = h(n.currentProvinces, n.currentOffice.province), t(s(f, 2).then(function(i) {
                            n.currentCitys = i;
                            o("#city", n.currentCitys, n.currentOffice.city);
                            c("#city", "#district", i);
                            var r = h(n.currentCitys, n.currentOffice.city);
                            (n.currentOffice.district || n.currentOffice.city && !n.currentOffice.district) && t(s(r, 3).then(function(t) {
                                n.currentDistricts = t;
                                o("#district", n.currentDistricts, n.currentOffice.district)
                            }), 200)
                        }), 200))
                    })
                },
                c = function(i, r, u) {
                    var f = e.find(i),
                        h = e.find(r);
                    f.change(function() {
                        var e, c, l;
                        if (h) {
                            if (e = f.val(), c = r == "#city" ? 2 : 3, !e) {
                                c == 2 && (n.currentCitys = [], n.currentOffice.city = null);
                                t(function() {
                                    n.currentDistricts = [];
                                    n.currentOffice.district = null
                                }, 200);
                                return
                            }
                            if (c == 2 && (n.currentDistricts = []), l = _.filter(u, {
                                    areaName: e
                                }), e == "北京市" || e == "天津市" || e == "上海市" || e == "重庆市" || e == "澳门特别行政区" || e == "香港特别行政区") {
                                if (i == "#province") {
                                    n.currentCitys = [{
                                        areaName: e
                                    }];
                                    n.currentDistricts = [];
                                    o("#city", n.currentCitys, undefined);
                                    o("#district", n.currentDistricts, undefined);
                                    return
                                }
                                l = _.filter(n.currentProvinces, {
                                    areaName: e
                                })
                            }
                            if (l && l.length == 0) return;
                            s(l[0].areaCode, c).then(function(t) {
                                c == 2 ? n.currentCitys = t : n.currentDistricts = t
                            })
                        }
                    })
                },
                p = function() {
                    n.currentOffice ? n.currentOffice.officeLocaltion && n.currentOffice.officeLocaltion.lng ? (r.keys.lng = n.currentOffice.officeLocaltion.lng, r.keys.lat = n.currentOffice.officeLocaltion.lat, r.keys.location = n.currentOffice.officeLocaltion.location) : (r.keys.lng = 116.331398, r.keys.lat = 39.92556) : (r.keys.lng = 116.331398, r.keys.lat = 39.92556);
                    r.keys.radius = n.currentOffice && n.currentOffice.officeLocaltion && n.currentOffice.officeLocaltion.radius ? n.currentOffice.officeLocaltion.radius : 500;
                    r.loadBaiduMapSdkAsync().then(function() {
                        n.isEnableDropMap = !0
                    })
                };
            (function() {
                n.save = a;
                n.isEnableDropMap = !1;
                n.currentProvinces = [];
                n.currentCitys = [];
                n.currentDistricts = [];
                l();
                n.isAres3 = window.Ares3;
                n.$watch("currentOffice", function() {
                    n.currentOffice && n.initialize && (p(), y(), v(), n.initialize = !1)
                });
                n.$watch("currentCitys", function() {
                    o("#city", n.currentCitys, undefined);
                    c("#city", "#district", n.currentCitys)
                });
                n.$watch("currentDistricts", function() {
                    o("#district", n.currentDistricts, undefined)
                });
                n.$watch("currentOffice.province", function() {
                    n.currentOffice && n.currentOffice.province && n.currentOffice.province.length > 0 && n.isEnableDropMap && r.setCityCenter(n.currentOffice.province)
                });
                n.$watch("currentOffice.city", function() {
                    n.currentOffice && n.currentOffice.city && n.currentOffice.city.length > 0 && n.isEnableDropMap && r.setCityCenter(n.currentOffice.city)
                });
                n.$watch("currentOffice.district", function() {
                    n.currentOffice && n.currentOffice.district && n.currentOffice.district.length > 0 && n.isEnableDropMap && r.setCityCenter(n.currentOffice.district)
                })
            })()
        }
    }
}]);
practiceModule.directive("officeInfoView", ["$log", "$timeout", function() {
    "use strict";
    return {
        templateUrl: "/app/tenant/views/office-info-view.html",
        controller: "OfficeInfoCtrl",
        link: function() {}
    }
}]);
practiceModule.directive("officeInvoiceEditView", ["$log", "$timeout", "$q", "baiduAreaSvc", function(n, t, i, r) {
    "use strict";
    return {
        templateUrl: "/app/tenant/views/office-invoice-edit-view.html",
        controller: "officeInvoiceEditCtrl",
        link: function(n, u) {
            var h = function() {
                    n.isEdit = n.isEdit ? !1 : !0
                },
                e = function(t, u) {
                    var f = i.defer();
                    return n.criteria = {
                        areaCode: t,
                        areaType: u
                    }, r.getSubBaiduAreas(n.criteria).success(function(n) {
                        f.resolve(n)
                    }).error(function(n) {
                        f.reject(n)
                    }), f.promise
                },
                f = function(n, t, i) {
                    var f = u.find(n),
                        r = "",
                        e;
                    switch (n) {
                        case "#province":
                            r = "省";
                            break;
                        case "#city":
                            r = "市";
                            break;
                        case "#district":
                            r = "区"
                    }
                    e = f.kendoDropDownList({
                        dataSource: t,
                        optionLabel: r,
                        dataTextField: "areaName",
                        dataValueField: "areaName",
                        value: i,
                        select: function(n) {
                            i = this.dataItem(n.item)[this.options.dataValueField] || null
                        }
                    }).data("kendoDropDownList")
                },
                o = function(n, t) {
                    var r = 1,
                        i = _.filter(n, {
                            areaName: t
                        });
                    return i && i.length > 0 && (r = i[0].areaCode), r
                },
                c = function() {
                    e(1, 1).then(function(i) {
                        var r, u, h;
                        if (n.currentProvinces = i, f("#province", n.currentProvinces, n.invoice.province), s("#province", "#city", n.currentProvinces), r = n.invoice.province, r == "北京市" || r == "天津市" || r == "上海市" || r == "重庆市" || r == "澳门特别行政区" || r == "香港特别行政区") {
                            n.currentCitys = [{
                                areaName: r
                            }];
                            n.currentDistricts = [];
                            f("#city", n.currentCitys, n.invoice.city);
                            u = o(n.currentProvinces, r);
                            (n.invoice.district || n.invoice.city && !n.invoice.district) && t(e(u, 3).then(function(t) {
                                n.currentDistricts = t;
                                f("#district", n.currentDistricts, n.invoice.district)
                            }), 200);
                            return
                        }
                        n.invoice.province && (h = o(n.currentProvinces, n.invoice.province), t(e(h, 2).then(function(i) {
                            n.currentCitys = i;
                            f("#city", n.currentCitys, n.invoice.city);
                            s("#city", "#district", i);
                            var r = o(n.currentCitys, n.invoice.city);
                            (n.invoice.district || n.invoice.city && !n.invoice.district) && t(e(r, 3).then(function(t) {
                                n.currentDistricts = t;
                                f("#district", n.currentDistricts, n.invoice.district)
                            }), 200)
                        }), 200))
                    })
                },
                s = function(i, r, o) {
                    var s = u.find(i),
                        h = u.find(r);
                    s.change(function() {
                        var u, c, l;
                        if (h) {
                            if (u = s.val(), c = r == "#city" ? 2 : 3, !u) {
                                c == 2 && (n.currentCitys = [], n.currentReceive.city = null);
                                t(function() {
                                    n.currentDistricts = [];
                                    n.currentReceive.district = null
                                }, 200);
                                return
                            }
                            if (c == 2 && (n.currentDistricts = []), l = _.filter(o, {
                                    areaName: u
                                }), u == "北京市" || u == "天津市" || u == "上海市" || u == "重庆市" || u == "澳门特别行政区" || u == "香港特别行政区") {
                                if (i == "#province") {
                                    n.currentCitys = [{
                                        areaName: u
                                    }];
                                    n.currentDistricts = [];
                                    f("#city", n.currentCitys, undefined);
                                    f("#district", n.currentDistricts, undefined);
                                    return
                                }
                                l = _.filter(n.currentProvinces, {
                                    areaName: u
                                })
                            }
                            if (l && l.length == 0) return;
                            e(l[0].areaCode, c).then(function(t) {
                                c == 2 ? n.currentCitys = t : n.currentDistricts = t
                            })
                        }
                    })
                };
            (function() {
                n.isEdit = !1;
                n.edit = h;
                n.init().then(function() {
                    c()
                });
                n.$watch("currentCitys", function() {
                    f("#city", n.currentCitys, undefined);
                    s("#city", "#district", n.currentCitys)
                });
                n.$watch("currentDistricts", function() {
                    f("#district", n.currentDistricts, undefined)
                })
            })()
        }
    }
}]);
tenantModule.directive("officeListView", ["$log", "$timeout", "appNav", function(n, t) {
    "use strict";
    return {
        restrict: "E",
        controller: "OfficeListCtrl",
        templateUrl: "/app/tenant/views/office-list-view.html",
        link: function(n, i) {
            var r = null,
                u = function() {
                    if (n.offices) {
                        var u = $(i).find("#officeList");
                        r = u.kendoGrid({
                            dataSource: {
                                data: n.offices
                            },
                            scrollable: !1,
                            sortable: !0,
                            selectable: "single",
                            change: function() {
                                var i = this.dataItem(this.select());
                                t(function() {
                                    n.$apply(function() {
                                        n.selectedItem = i ? i : null
                                    })
                                })
                            },
                            columns: [{
                                field: "name",
                                title: "名称",
                                width: "120px",
                                attributes: {
                                    "class": "cell-left"
                                }
                            }, {
                                field: "abbreviation",
                                title: "诊所简称",
                                width: "60px"
                            }, {
                                field: "phoneNumber",
                                title: "诊所电话",
                                width: "60px"
                            }, {
                                field: "faxNumber",
                                title: "传真",
                                width: "60px"
                            }, {
                                field: "postalCode",
                                title: "邮编",
                                width: "60px"
                            }, {
                                field: "address",
                                title: "地址",
                                width: "200px",
                                attributes: {
                                    "class": "cell-left"
                                }
                            }, {
                                field: "contactName",
                                title: "联系人",
                                width: "60px"
                            }, {
                                field: "contactPhoneNumber",
                                title: "联系电话",
                                width: "60px"
                            }, {
                                field: "website",
                                title: "网址",
                                width: "120px"
                            }, ]
                        }).data("kendoGrid")
                    }
                },
                f = function() {
                    var f, t, e;
                    r ? (r.dataSource.data(n.offices), n.selectedItem && (f = r.dataSource, t = f.get(n.selectedItem.id), t && (e = $(i).find("#officeList").find("tbody>tr[data-uid=" + t.uid + "]"), r.select(e)), n.selectedItem = t)) : u()
                };
            (function() {
                n.isAres3 = window.Ares3;
                n.$watch("offices", function() {
                    f()
                })
            })()
        }
    }
}]);
tenantModule.directive("officeOnliceConsultCreateFieldView", ["$log", "$timeout", "$state", "aresDialog", "officeOptionSvc", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        scope: {
            bigType: "="
        },
        templateUrl: "/app/tenant/views/office-onlice-consult-create-field-view.html",
        controller: "OfficeOnliceConsultCreateFieldCtrl",
        link: function(n) {
            var t = function(t, i) {
                    t.target.localName == "li" && ($(t.target).parents("ul").find("li").removeClass("selected"), $(t.target).addClass("selected"), n.selectedItem = i)
                },
                i = function(t) {
                    if (!n.selectedItem) {
                        r.info("提示", "请选中一项！");
                        return
                    }
                    n.getOnlineConsultCreateInfoFieldsConfig().then(function(i) {
                        var u = _.find(i, {
                            text: n.selectedItem.text,
                            bigType: n.selectedItem.bigType
                        });
                        u ? !u.isCanConfig && (u.isCanConfig || u.isEnabled) ? r.info("提示", "该项不可配置！") : (u.isEnabled = t, n.saveOnlineConsultCreateInfoFieldsConfig()) : r.info("提示", "请选中一项！")
                    })
                },
                f = function(t) {
                    n.getOnlineConsultCreateInfoFieldsConfig().then(function(i) {
                        var r = _.filter(i, {
                            bigType: n.bigType
                        });
                        r && (_.each(r, function(n) {
                            n.isCanConfig && (n.isEnabled = t)
                        }), n.saveOnlineConsultCreateInfoFieldsConfig())
                    })
                },
                e = function() {
                    r.confirm("提示", "确认要恢复初始值？").then(function() {
                        var t = u.optionDefaultValues.OnlineConsultCreateInfoFieldsDefaultConfig;
                        n.getOnlineConsultCreateInfoFieldsConfig().then(function(i) {
                            _.each(i, function(i) {
                                if (i.bigType == n.bigType) {
                                    var r = _.find(t, {
                                        text: i.text
                                    });
                                    r && (i.isEnabled = r.isEnabled, i.isRequired = r.isRequired)
                                }
                            });
                            n.saveOnlineConsultCreateInfoFieldsConfig()
                        })
                    })
                },
                o = function(t) {
                    n.getOnlineConsultCreateInfoFieldsConfig().then(function(i) {
                        var r = _.find(i, {
                            name: t.name
                        });
                        r && (r.isRequired = !r.isRequired, n.saveOnlineConsultCreateInfoFieldsConfig())
                    })
                },
                s = function(t) {
                    n.getOnlineConsultCreateInfoFieldsConfig().then(function(i) {
                        var r = _.find(i, {
                            name: t.name
                        });
                        r && n.saveOnlineConsultCreateInfoFieldsConfig()
                    })
                };
            (function() {
                n.setThisSelected = t;
                n.changeFieldEnabled = i;
                n.changeThisTypeFieldsEnabled = f;
                n.reInitThisTypeFields = e;
                n.changeRequired = o;
                n.changeTempPatientRequired = s
            })()
        }
    }
}]);
tenantModule.directive("officeOnliceConsultCreateRequiredView", ["$log", function() {
    "use strict";
    return {
        restrict: "AE",
        templateUrl: "/app/tenant/views/office-onlice-consult-create-required-view.html",
        link: function(n) {
            (function() {
                n.patientType = "患者信息";
                n.revisitType = "执行回访信息"
            })()
        }
    }
}]);
tenantModule.directive("officeOrgMgmtView", ["$timeout", "$modal", "$compile", "enums", "officeSvc", "aresDialog", "loginContext", "appNav", "dataDicSvc", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/office-org-mgmt-view.html",
        link: function(n, i) {
            var c = u.adminOffice,
                o, e, v = function() {
                    var n = new kendo.data.HierarchicalDataSource({
                        transport: {
                            read: function(n) {
                                if (!n.data.id) {
                                    n.success([{
                                        id: c.id,
                                        hasChildren: !0,
                                        abbreviation: "公司",
                                        isLeaf: !1,
                                        icon: "icon icon-company"
                                    }]);
                                    return
                                }
                                u.getOfficeNodesByParent(n.data.id).success(function(t) {
                                    t && t.length > 0 && angular.forEach(t, function(n) {
                                        n.icon = n.isLeaf ? "icon icon-office" : "icon icon-group";
                                        n.bizType == 1 && (n.icon += "-shared")
                                    });
                                    n.success(t)
                                }).error(function(t) {
                                    n.error(t)
                                })
                            }
                        },
                        schema: {
                            model: {
                                id: "id",
                                hasChildren: "hasChildren"
                            }
                        }
                    });
                    o = i.find("#treeview").kendoTreeView({
                        dataSource: n,
                        dataTextField: "name",
                        template: '<div><span class="#= item.icon #"><\/span> #= item.abbreviation #<\/div>'
                    }).data("kendoTreeView")
                },
                y = function() {
                    e = i.find("#menu").kendoContextMenu({
                        target: "#treeview",
                        select: function(n) {
                            var i = o.select(),
                                t = o.dataItem(i);
                            t || n.preventDefault();
                            n.item.classList.contains("menu-item-clinic") && d(t);
                            n.item.classList.contains("menu-item-group") && k(t);
                            n.item.classList.contains("menu-item-edit") && (t.isLeaf ? b(t) : w(t));
                            n.item.classList.contains("menu-item-remove") && tt(t)
                        },
                        open: function(n) {
                            o.select(n.event.target);
                            var t = o.dataItem(n.event.target);
                            t || n.preventDefault();
                            p(t)
                        }
                    }).data("kendoContextMenu")
                },
                p = function(n) {
                    e.enable(".menu-item-clinic", !0);
                    e.enable(".menu-item-group", !0);
                    e.enable(".menu-item-remove", !0);
                    e.enable(".menu-item-edit", !0);
                    n.isLeaf && (e.enable(".menu-item-clinic", !1), e.enable(".menu-item-group", !1));
                    !n.isLeaf && n.hasChildren && e.enable(".menu-item-remove", !1);
                    n.id === c.id && e.enable(".menu-item-edit", !1)
                },
                w = function(n) {
                    a(n, r.ViewMode.Edit).then(function(n) {
                        n && h()
                    })
                },
                b = function(n) {
                    l(n, r.ViewMode.Edit).then(function(n) {
                        n && h()
                    })
                },
                k = function(n) {
                    a(n, r.ViewMode.Add).then(function(n) {
                        n && h()
                    })
                },
                d = function(n) {
                    l(n, r.ViewMode.Add).then(function(n) {
                        n && h()
                    })
                },
                g = function(t) {
                    u.getTenantRootGroup().success(function(i) {
                        i ? (n.rootGroup = i, nt(t).then(function(n) {
                            n && u.transferOffices(n).success(function() {
                                f.info("提示", "迁移成功");
                                h()
                            })
                        })) : f.warning("提示", "公司没有根群组，无法迁移！")
                    })
                },
                l = function(n, i) {
                    return t.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<office-edit-view><\/office-edit-view>",
                        controller: "OfficeEditCtrl",
                        windowClass: "small-dialog",
                        size: "sm",
                        resolve: {
                            host: function() {
                                return {
                                    viewMode: i,
                                    id: n.id,
                                    isOfficeTypeVisible: !0,
                                    isVersionSelectable: !0
                                }
                            }
                        }
                    }).result
                },
                a = function(n, i) {
                    return t.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<group-edit-view><\/group-edit-view>",
                        controller: "GroupEditCtrl",
                        windowClass: "small-dialog",
                        size: "sm",
                        resolve: {
                            host: function() {
                                return {
                                    viewMode: i,
                                    id: n.id
                                }
                            }
                        }
                    }).result
                },
                nt = function() {
                    return t.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<office-transfer-dialog-view><\/office-transfer-dialog-view>",
                        controller: "OfficeTransferDialogCtrl",
                        windowClass: "small-dialog",
                        size: "sm",
                        resolve: {
                            host: function() {
                                return {
                                    rootGroupId: n.rootGroup.id
                                }
                            }
                        }
                    }).result
                },
                tt = function(n) {
                    f.confirm("删除诊所", "您确认要删除诊所【" + n.name + "】吗？").then(function() {
                        u.logicDelete(n.id).success(function() {
                            h()
                        })
                    })
                },
                h = function() {
                    s.officeInfoDic.clearCache();
                    o.dataSource.read();
                    o.expand(".k-item")
                };
            (function() {
                v();
                y();
                n.transferOffice = g
            })()
        }
    }
}]);
tenantModule.directive("officePatientFieldView", ["$log", "$timeout", "$state", "aresDialog", "officeOptionSvc", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        scope: {
            bigType: "="
        },
        templateUrl: "/app/tenant/views/office-patient-field-view.html",
        controller: "OfficePatientFieldCtrl",
        link: function(n) {
            var i = function(t, i) {
                    t.target.localName == "li" && ($(t.target).parents("ul").find("li").removeClass("selected"), $(t.target).addClass("selected"), n.selectedItem = i)
                },
                f = function(t) {
                    if (!n.selectedItem) {
                        r.info("提示", "请选中一项！");
                        return
                    }
                    n.getPatientInfoFieldsConfig().then(function(i) {
                        var u = _.find(i, {
                            text: n.selectedItem.text
                        });
                        u ? u.isCanConfig ? (u.isEnabled = t, n.savePatientInfoFieldsConfig()) : r.info("提示", "该项不可配置！") : r.info("提示", "请选中一项！")
                    })
                },
                e = function(t) {
                    n.getPatientInfoFieldsConfig().then(function(i) {
                        var r = _.filter(i, {
                            bigType: n.bigType
                        });
                        r && (_.each(r, function(n) {
                            n.isCanConfig && (n.isEnabled = t)
                        }), n.savePatientInfoFieldsConfig())
                    })
                },
                o = function() {
                    r.confirm("提示", "确认要恢复初始值？").then(function() {
                        var t = u.optionDefaultValues.PatientInfoFieldsDefaultConfig;
                        n.getPatientInfoFieldsConfig().then(function(i) {
                            _.each(i, function(i) {
                                if (i.bigType == n.bigType) {
                                    var r = _.find(t, {
                                        text: i.text
                                    });
                                    r && (i.isEnabled = r.isEnabled, i.isRequired = r.isRequired, i.isTempPatientRequired = r.isRequired)
                                }
                            });
                            n.savePatientInfoFieldsConfig()
                        })
                    })
                },
                s = function(i) {
                    t(i, !0) || n.getPatientInfoFieldsConfig().then(function(t) {
                        var r = _.find(t, {
                            name: i.name
                        });
                        r && (r.isRequired = !r.isRequired, n.savePatientInfoFieldsConfig())
                    })
                },
                h = function(i) {
                    t(i, !1) || n.getPatientInfoFieldsConfig().then(function(t) {
                        var r = _.find(t, {
                            name: i.name
                        });
                        r && (r.isTempPatientRequired = !r.isTempPatientRequired, n.savePatientInfoFieldsConfig())
                    })
                },
                t = function(n, t) {
                    return n.name !== "patientName" ? !1 : t && n.isRequired || !t && n.isTempPatientRequired ? (r.info("提示", "患者姓名不可设置"), !0) : !1
                };
            (function() {
                n.setThisSelected = i;
                n.changeFieldEnabled = f;
                n.changeThisTypeFieldsEnabled = e;
                n.reInitThisTypeFields = o;
                n.changeRequired = s;
                n.changeTempPatientRequired = h
            })()
        }
    }
}]);
tenantModule.directive("officePatientRequiredView", ["$log", function() {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/office-patient-required-view.html",
        controller: "OfficePatientRequiredCtrl",
        link: function(n) {
            (function() {
                n.infoType = "个人信息";
                n.linkType = "联系方式";
                n.patientType = "患者信息";
                n.FirstType = "首诊信息";
                n.isAres3 = window.Ares3
            })()
        }
    }
}]);
practiceModule.directive("officePointView", ["$log", "$timeout", "$window", "appNav", "gridOptionUtil", "officeSvc", "enums", function(n, t, i, r, u, f, e) {
    "use strict";
    return {
        templateUrl: "/app/tenant/views/office-point-view.html",
        controller: "officePointCtrl",
        link: function(n, t) {
            var v = function() {
                    r.goToShortMessage()
                },
                o = 10,
                h, c, s = {
                    pageIndex: 1,
                    pageSize: o
                },
                l = i.innerHeight - 265,
                y = [{
                    field: "name",
                    title: "任务名称",
                    width: "100px",
                    headerAttributes: {
                        "class": "title-cell"
                    },
                    attributes: {
                        "class": "cell-left"
                    }
                }, {
                    field: "description",
                    title: "获取规则",
                    width: "150px",
                    headerAttributes: {
                        "class": "title-cell"
                    },
                    attributes: {
                        "class": "cell-left"
                    }
                }, {
                    field: "pointStr",
                    title: "赠送积分",
                    width: "50px"
                }, {
                    field: "validDateStr",
                    title: "有效期",
                    width: "100px"
                }, {
                    field: "comments",
                    title: "备注",
                    width: "80px",
                    template: function(n) {
                        var t = n.notes;
                        if (t) {
                            if (t.indexOf("http") >= 0) return '<div class="know-more-info"><a href=' + t + ' target="_blank">了解更多<\/a><\/div>';
                            if (t.indexOf("/#/") >= 0) return '<div class="know-more-info"><a href=' + t + ' target="_self">赚取积分<\/a><\/div>'
                        }
                        return t
                    }
                }, ],
                p = [{
                    field: "transactionTimeStr",
                    title: "时间",
                    width: "120px"
                }, {
                    field: "point",
                    title: "积分变动",
                    width: "120px",
                    template: function(n) {
                        return n.isExpired ? "<span>" + n.point + "<\/span><span>(已过期)<\/span>" : "<span>" + n.point + "<\/span>"
                    }
                }, {
                    field: "notes",
                    title: "详细说明",
                    width: "80px"
                }, ],
                w = function() {
                    var r = t.find("#pointTask"),
                        i = u.getDefaultGridOption({
                            transport: {
                                read: function(t) {
                                    var i = {
                                        pageIndex: t.data.page || s.pageIndex,
                                        pageSize: t.data.pageSize || s.pageSize,
                                        pointType: e.PointType.EnterprisePoint
                                    };
                                    f.getOfficePointRules(i).then(function(i) {
                                        n.taskData = i;
                                        i.data.items || (i.data.items = []);
                                        i.data.items.length > 0 && _.each(i.data.items, function(n) {
                                            n.pointStr = "+" + n.enterprisePoint;
                                            n.validDateStr = moment(n.fromDate).format("YYYY.MM.DD") + " - " + moment(n.toDate).format("YYYY.MM.DD")
                                        });
                                        t.success({
                                            data: i.data.items,
                                            total: i.data.totalCount
                                        })
                                    })
                                }
                            },
                            pageSize: o,
                            serverPaging: !0,
                            schema: {
                                data: "data",
                                total: "total"
                            }
                        }, y, l);
                    i.pageable = u.getPageable(o);
                    h = r.kendoGrid(i).data("kendoGrid")
                },
                b = function() {
                    var r = t.find("#pointDetail"),
                        i = u.getDefaultGridOption({
                            transport: {
                                read: function(t) {
                                    n.criteria = {
                                        pageIndex: t.data.page || s.pageIndex,
                                        pageSize: t.data.pageSize || s.pageSize
                                    };
                                    f.getOfficePointDetail(n.criteria).then(function(i) {
                                        n.data = i;
                                        i.data.items || (i.data.items = []);
                                        i.data.items.length > 0 && _.each(i.data.items, function(n) {
                                            n.transactionTimeStr = moment(n.transactionTime).format("YYYY-MM-DD HH:mm:ss")
                                        });
                                        t.success({
                                            data: i.data.items,
                                            total: i.data.totalCount
                                        })
                                    })
                                }
                            },
                            pageSize: o,
                            serverPaging: !0,
                            schema: {
                                data: "data",
                                total: "total"
                            }
                        }, p, l);
                    i.pageable = u.getPageable(o);
                    c = r.kendoGrid(i).data("kendoGrid")
                },
                k = function() {
                    h ? h.dataSource.read() : w()
                },
                d = function() {
                    c ? c.dataSource.read() : b()
                },
                a = function(t) {
                    switch (t) {
                        case "task":
                            n.isShowDetail = "task";
                            k();
                            break;
                        case "detail":
                            n.isShowDetail = "detail";
                            d()
                    }
                };
            (function() {
                n.goToMessage = v;
                n.isShowDetail = "task";
                n.toggleTab = a;
                a("task")
            })()
        }
    }
}]);
tenantModule.directive("officeTodayworkManagementView", ["$log", "$timeout", "$state", "appNav", "aresDialog", function(n, t) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/office-todaywork-management-view.html",
        controller: "officeTodayworkManagementCtrl",
        link: function(n) {
            var i = function() {
                    n.saveConfig()
                },
                r = function() {
                    n.isEdit = !n.isEdit
                },
                u = function() {
                    n.initData().then(function() {
                        t(function() {
                            n.isEdit = !1
                        })
                    })
                };
            (function() {
                n.editConfig = r;
                n.save = i;
                n.cancel = u
            })()
        }
    }
}]);
tenantModule.directive("partnerAccountManagementView", ["$log", "$timeout", "$state", "$modal", function(n, t, i, r) {
    return {
        templateUrl: "/app/tenant/views/partner-account-management-view.html",
        controller: "PartnerAccountManagementCtrl",
        link: function(n) {
            var t = function(t, i) {
                var i = i || [],
                    t = t,
                    u = "",
                    f;
                u = t === 1 ? "修改账号" : "新建账号";
                f = r.open({
                    animation: !0,
                    backdrop: "static",
                    template: "<partner-account-dialog-view><\/partner-account-dialog-view>",
                    controller: "PartnerAccountDialogCtrl",
                    size: "md",
                    resolve: {
                        host: function() {
                            return {
                                title: u,
                                type: t,
                                item: i
                            }
                        }
                    }
                });
                f.result.then(function() {
                    n.search()
                })
            };
            (function() {
                n.addPartnerAccount = t
            })()
        }
    }
}]);
practiceModule.directive("practiceOfficeUploadView", ["$log", "$timeout", "$state", function() {
    return {
        restrict: "A",
        scope: {
            officeId: "=",
            add: "&",
            send: "&",
            start: "&",
            stop: "&",
            fail: "&",
            destroy: "&",
            done: "&",
            uploadprogress: "&"
        },
        link: function(n, t) {
            function i(n, t) {
                var i = {
                    dataType: "json",
                    type: "POST",
                    sequentialUploads: !0,
                    autoUpload: !0,
                    multipart: !1
                };
                n.add && (i.add = function(t, i) {
                    n.$apply(function() {
                        n.add({
                            e: t,
                            data: i
                        })
                    })
                });
                n.fail && (i.fail = function(t, i) {
                    n.$apply(function() {
                        n.fail({
                            e: t,
                            data: i
                        })
                    })
                });
                n.done && (i.done = function(t, i) {
                    n.$apply(function() {
                        n.done({
                            e: t,
                            data: i
                        })
                    })
                });
                n.uploadprogress && (i.progress = function(t, i) {
                    n.$apply(function() {
                        n.uploadprogress({
                            e: t,
                            data: i
                        })
                    })
                });
                t.fileupload(i)
            }(function() {})(i(n, t))
        }
    }
}]);
practiceModule.directive("providerAppendView", ["$log", "$timeout", "$window", "$q", "dataDicSvc", "loginContext", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/tenant/views/provider-append-view.html",
        link: function(n, f) {
            var s = Ares.kendoGridUtil(i, n),
                e = null,
                h = function() {
                    var n = this;
                    $(f).find("#providerList table tbody tr").each(function(t, i) {
                        var r = n.dataItem(i);
                        r.isWorkingInCurrentOffice ? $("td.cell-command", i).find('button[data-action="append"]').remove() : $("td.cell-command", i).find('button[data-action="remove"]').remove()
                    })
                },
                c = function() {
                    var n = r.defer(),
                        t = [{
                            field: "officeName",
                            title: "所属诊所",
                            width: "80px"
                        }, {
                            field: "name",
                            title: "姓名",
                            width: "80px"
                        }, {
                            field: "employeeNo",
                            title: "员工号",
                            width: "60px"
                        }, {
                            field: "sexStr",
                            title: "性别",
                            width: "60px"
                        }, {
                            field: "job",
                            title: "岗位",
                            width: "80px"
                        }, {
                            field: "workingOfficeStr",
                            title: "工作诊所",
                            width: "150px",
                            attributes: {
                                "class": "cell-left"
                            }
                        }, {
                            field: "user.roleStr",
                            title: "所属角色",
                            width: "150px",
                            attributes: {
                                "class": "cell-left"
                            }
                        }, {
                            template: s.commandTemplate,
                            title: "",
                            width: "60px",
                            attributes: {
                                "class": "cell-command"
                            }
                        }];
                    return u.departmentDic.load().then(function(i) {
                        var r = i && i.length > 0;
                        r && t.splice(1, 0, {
                            field: "department",
                            title: "科室",
                            width: "80px"
                        });
                        n.resolve(t)
                    }), n.promise
                },
                l = function() {
                    n.providers && c().then(function(t) {
                        var u = $(f).find("#providerList"),
                            i, r;
                        e = u.kendoGrid({
                            dataSource: n.providers,
                            height: 500,
                            scrollable: !0,
                            sortable: !0,
                            selectable: "single",
                            columns: t,
                            dataBound: h
                        }).data("kendoGrid");
                        i = t[0];
                        r = [{
                            field: i.field,
                            dir: "desc"
                        }];
                        e.dataSource.sort(r)
                    })
                },
                o = function() {
                    e ? e.dataSource.data(n.providers) : l()
                },
                a = [{
                    text: "授权登录当前诊所",
                    action: "append",
                    icon: "glyphicon-plus"
                }, {
                    text: "取消当前诊所登录授权",
                    action: "remove",
                    icon: "glyphicon-minus"
                }, ],
                v = function(t, i, r) {
                    switch (i) {
                        case "append":
                            n.appendProvider(r);
                            break;
                        case "remove":
                            n.removeProvider(r)
                    }
                },
                y = function() {
                    u.officeDic.loadActive().then(function(t) {
                        t = _.reject(t, {
                            id: n.officeId
                        });
                        f.find("#officeInput").kendoDropDownList({
                            dataSource: t,
                            dataTextField: "name",
                            dataValueField: "id",
                            optionLabel: "全部诊所",
                            select: function(t) {
                                n.criteria.officeId = this.dataItem(t.item)[this.options.dataValueField] || null
                            }
                        })
                    })
                };
            (function() {
                n.commands = a;
                n.onCommandClick = v;
                n.refreshGrid = o;
                y();
                n.$watch("providers", function() {
                    o()
                })
            })();
            t(function() {
                Ares.centerModal(f.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
patientModule.directive("providerEditView", ["$log", "$timeout", "$q", "$modal", "practiceSvc", "dataDicSvc", "loginContext", "aresDialog", "moduleOptionProvider", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    return {
        templateUrl: "/app/tenant/views/provider-edit-view.html",
        controller: "ProviderEditCtrl",
        link: function(n, i) {
            var c, h, y = function() {
                    c = Ares.validateForm(i.find("#providerForm"), {
                        providerName: "required",
                        employeeNo: "required",
                        account: {
                            required: !0,
                            minlength: 3
                        },
                        password: {
                            required: !0,
                            minlength: 6,
                            passwordCn: !0
                        },
                        confirmPassword: {
                            required: !0,
                            equalTo: "#password"
                        },
                        roles: "required",
                        birth: {
                            dateCn: !0,
                            dateMax: !0
                        },
                        identityCard: {
                            identityCard: !0
                        }
                    }, {
                        providerName: "请输入姓名",
                        employeeNo: "员工号不能为空",
                        account: {
                            required: "请输入登录账号",
                            minlength: "登录账号至少3位"
                        },
                        password: {
                            required: "请输入登录密码",
                            minlength: "登录密码至少6位"
                        },
                        confirmPassword: {
                            required: "请输入确认密码",
                            equalTo: "两次输入的密码不一致"
                        },
                        roles: "请选择所属角色",
                        birth: {
                            dateCn: "请输入合法的日期",
                            dateMax: "生日不能大于当前时间！"
                        },
                        identityCard: {
                            identityCard: "请输入正确的身份证号码!"
                        }
                    })
                },
                p = function() {
                    i.find("#officeInput").kendoDropDownList({
                        dataSource: n.offices,
                        dataTextField: "name",
                        dataValueField: "id",
                        value: n.currentProvider ? n.currentProvider.officeId : e.officeId,
                        select: function(t) {
                            var r = this.dataItem(t.item)[this.options.dataValueField] || null,
                                i;
                            n.currentProvider.officeId = r;
                            n.workingOfficesEdit = n.$root.isTenantAdmin;
                            i = n.offices.find(function(n) {
                                return n.id === r
                            });
                            i && i.officeType && i.officeType === 1 && (n.workingOfficesEdit = !1);
                            Ares.sensors.trackDropDownEvent("ProviderEdit", "诊所")
                        }
                    })
                },
                w = function() {
                    var t = i.find("#job"),
                        r = t.kendoDropDownList({
                            dataSource: n.jobs,
                            dataTextField: "itemName",
                            dataValueField: "itemName",
                            value: n.currentProvider ? n.currentProvider.job : null,
                            select: function(t) {
                                n.currentProvider.job = this.dataItem(t.item)[this.options.dataValueField] || null;
                                v();
                                Ares.sensors.trackDropDownEvent("ProviderEdit", "岗位")
                            }
                        })
                },
                b = function() {
                    f.doctorDic.loadActive().then(function() {
                        var t = i.find("#relatedDoctorInput");
                        t.kendoDropDownList({
                            dataSource: n.doctors,
                            optionLabel: "未指定医生",
                            dataTextField: "name",
                            dataValueField: "id",
                            value: n.currentProvider ? n.currentProvider.relatedProviderId : null,
                            select: function(t) {
                                n.currentProvider.relatedProviderId = this.dataItem(t.item)[this.options.dataValueField] || null;
                                Ares.sensors.trackDropDownEvent("ProviderEdit", "关联医生")
                            }
                        })
                    })
                },
                k = function() {
                    var t = n.providers.filter(function(t) {
                            return t.job == n.currentProvider.job && !t.isIntern && t.show && t.userID && t.userID > 0
                        }),
                        r = i.find("#instructor");
                    r.kendoDropDownList({
                        dataSource: t,
                        optionLabel: "未指定带教老师",
                        dataTextField: "name",
                        dataValueField: "id",
                        value: n.currentProvider ? n.currentProvider.instructorId : null,
                        select: function(t) {
                            n.currentProvider.instructorId = this.dataItem(t.item)[this.options.dataValueField] || null;
                            Ares.sensors.trackDropDownEvent("ProviderEdit", "带教老师")
                        }
                    })
                },
                l = function() {
                    var t = i.find("#department"),
                        r = t.kendoDropDownList({
                            dataSource: n.departments,
                            dataTextField: "itemName",
                            dataValueField: "itemName",
                            optionLabel: "未指定科室",
                            value: n.currentProvider ? n.currentProvider.department : null,
                            select: function(t) {
                                n.currentProvider.department = this.dataItem(t.item)[this.options.dataValueField] || null;
                                Ares.sensors.trackDropDownEvent("ProviderEdit", "科室")
                            }
                        })
                },
                d = function() {
                    var t = angular.copy(n.roles);
                    e.isTenantAdmin || (t = _.reject(t, {
                        isTenantAdministrator: !0
                    }), e.roleType !== "诊所管理员" && (t = _.reject(t, {
                        name: "诊所管理员"
                    })));
                    h = i.find("#roles").kendoMultiSelect({
                        dataTextField: "name",
                        dataValueField: "id",
                        dataSource: t
                    }).data("kendoMultiSelect");
                    h.enable(n.canEditUser)
                },
                g = function() {
                    var r = n.currentProvider.department,
                        u = i.find("#department"),
                        t;
                    u.val() != r && (t = u.data("kendoDropDownList"), t && t.select(function(n) {
                        return n.itemName === r
                    }))
                },
                nt = function() {
                    w();
                    l();
                    d();
                    p();
                    b();
                    k();
                    v();
                    it();
                    g()
                },
                tt = function() {
                    if (n.selectedOfficeIds = n.currentProvider.workingOffices.map(function(n) {
                            return n.id
                        }), a() && n.currentProvider.user && n.currentProvider.user.roles) {
                        var t = _.map(n.currentProvider.user.roles, function(n) {
                            return n.id
                        });
                        i.find("#roles").data("kendoMultiSelect").value(t)
                    }
                },
                it = function() {
                    var r = n.currentProvider.job,
                        u = i.find("#job"),
                        t;
                    u.val() != r && (t = u.data("kendoDropDownList"), t && t.select(function(n) {
                        return n.itemName === r
                    }))
                },
                rt = function(t) {
                    n.currentProvider.sex = t
                },
                ut = function(t) {
                    n.currentProvider.user.isNeedExtraValidate = t
                },
                ft = function(t) {
                    n.currentProvider.user.isMobileAppDisabled = t
                },
                et = function(t) {
                    n.currentProvider.user.isNeedDeviceValidate = t
                },
                ot = function() {
                    var t, r;
                    n.currentProvider.isUserEdited = n.canEditUser;
                    n.canEditUser && (t = i.find("#roles").data("kendoMultiSelect").value(), t && t.length > 0 ? (r = _.map(t, function(n) {
                        return {
                            id: n
                        }
                    }), n.currentProvider.user.roles = r) : n.currentProvider.user.roles = null)
                },
                a = function() {
                    return n.currentProvider.id > 0
                },
                st = function() {
                    var t, r;
                    if (ot(), i.find("#providerForm").valid()) {
                        if (t = /^(1[0-9\*]{10})$/, n.currentProvider.mobile && (n.currentProvider.mobile.length != 11 || !t.test(n.currentProvider.mobile))) {
                            o.warn("提示", "请填写正确的绑定手机号码！");
                            return
                        }
                        if (n.canEditUser && n.currentProvider.user.isNeedExtraValidate && (r = n.currentProvider.user.extraValidationMobile, r.length != 11 || !t.test(r))) {
                            o.warn("提示", "需要手机验证时必须填入正确的手机号！");
                            return
                        }
                        if (n.currentProvider.workingOffices.length == 0) {
                            o.warn("提示", "请选择工作诊所！");
                            return
                        }
                        if (!n.currentProvider.workingOffices.some(function(t) {
                                return n.currentProvider.officeId == t.id
                            })) {
                            o.warn("提示", "工作诊所必须包含所属诊所！");
                            return
                        }
                        n.currentProvider.birth = i.find("#birth").val();
                        n.saveProvider()
                    }
                },
                ht = function() {
                    return r.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<system-setting-item-edit><\/system-setting-item-edit>",
                        controller: "SystemSettingItemEditCtrl",
                        resolve: {
                            host: function() {
                                return {
                                    itemType: n.itemType
                                }
                            },
                            boxTitle: function() {
                                return ""
                            }
                        }
                    })
                },
                ct = function() {
                    n.itemType = "科室";
                    var t = ht();
                    t.result.then(function(t) {
                        t && (l(), u.getProvider(n.currentProvider.id).success(function(t) {
                            n.currentProvider.department = t.department
                        }).error(function(t) {
                            n.data.error = t.data
                        }))
                    })
                },
                v = function() {
                    t(function() {
                        n.isRelatedDoctorVisible = n.currentProvider.job == "牙医助理"
                    })
                },
                lt = function() {
                    y();
                    nt();
                    n.currentProvider.user = n.currentProvider.user || {};
                    c && Ares.clearError(i.find("#providerForm"));
                    n.currentProvider && tt();
                    n.$watch("canEditUser", function() {
                        h && h.enable(n.canEditUser)
                    })
                },
                at = function(t) {
                    t && t.length != 0 ? (n.selectedOfficeIds = t.map(function(n) {
                        return n.id
                    }), n.currentProvider.workingOffices = n.offices.filter(function(t) {
                        return n.selectedOfficeIds.some(function(n) {
                            return t.id == n
                        })
                    })) : (n.selectedOfficeIds = [], n.currentProvider.workingOffices = [])
                };
            (function() {
                n.today = new Date;
                n.setSex = rt;
                n.setNeedMobileValidate = ut;
                n.setMobileLogonDisabledOption = ft;
                n.isDeviceMgmtEnabled = s.isDeviceMgmtEnabled();
                n.onOfficeSelected = at;
                n.setNeedDeviceValidate = et;
                n.validAndSave = st;
                n.editDepartment = ct;
                n.canEditUser = !1;
                n.needSendMessage = !0;
                n.isEdit = a;
                n.initView = lt
            })()
        }
    }
}]);
tenantModule.directive("providerHomeView", ["$log", "$timeout", "$state", "$location", "appNav", "permissionProvider", "dataDicSvc", "moduleOptionProvider", "loginContext", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/provider-home-view.html",
        link: function(n) {
            var t = function() {
                var t = [new u.TabItem("providerSettings.providerList", "员工管理", "icon-user", "setting.provider", ["providerSettings.providerEdit"]), new u.TabItem("providerSettings.role", "角色管理", "icon-users", "setting.role"), ],
                    i = !1;
                e.officeSettingDic.load().then(function(r) {
                    t.push(new u.TabItem("providerSettings.patientHandOver", "人员交接", "icon-users", "setting.patientHandOver"));
                    i = r.isDeductionChargeEnabled;
                    i && t.push(new u.TabItem("providerSettings.chargeDeductionHandOver", "划扣执行交接", "icon-users", "setting.chargeDeductionHandOver"));
                    o.isPartnerMgmtEnabled() && s.isGroup && t.push(new u.TabItem("providerSettings.partnerAccountManagement", "外部账号管理", "icon-users", "setting.partnerUserManagement"));
                    n.states = t
                })
            };
            (function() {
                t()
            })()
        }
    }
}]);
practiceModule.directive("providerListView", ["$log", "$timeout", "$window", "$modal", "$q", "dataDicSvc", "loginContext", "permissionProvider", "practiceSvc", "gridOptionUtil", "kendoUtil", function(n, t, i, r, u, f, e, o, s, h, c) {
    "use strict";
    return {
        templateUrl: "/app/tenant/views/provider-list-view.html",
        controller: "ProviderListCtrl",
        link: function(n, t) {
            var w = Ares.kendoGridUtil(i, n),
                l = null,
                p = 5,
                b = function() {
                    var i = this;
                    $(t).find("#providerList table tbody tr").each(function(t, r) {
                        var f = i.dataItem(r),
                            u = $("td.cell-command", r);
                        n.isConnectYongyouHrp && u.find('button[data-action="delete"]').remove();
                        o.canEditProvider(f) ? e.isTenantAdmin ? (u.find('button[data-action="remove"]').remove(), f.user && f.user.account != null && f.user.account != "" || u.find('button[data-action="changePwd"]').remove()) : f.officeId != e.officeId ? u.find('button:not([data-action="remove"])').remove() : u.find('button[data-action="remove"]').remove() : u.find("button").remove()
                    })
                },
                k = function() {
                    var n = u.defer(),
                        t = [{
                            field: "officeName",
                            title: "所属诊所",
                            width: "80px"
                        }, {
                            field: "name",
                            title: "姓名",
                            width: "120px"
                        }, {
                            field: "employeeNo",
                            title: "员工号",
                            width: "60px",
                            sortable: {
                                compare: function(n, t) {
                                    return isNaN(n.employeeNo) || isNaN(t.employeeNo) ? n.employeeNo.localeCompare(t.employeeNo) : parseInt(n.employeeNo) - parseInt(t.employeeNo)
                                }
                            }
                        }, {
                            field: "sexStr",
                            title: "性别",
                            width: "50px"
                        }, {
                            field: "birthStr",
                            title: "生日",
                            width: "100px"
                        }, {
                            field: "job",
                            title: "岗位",
                            width: "80px"
                        }, {
                            field: "mobile",
                            title: "手机",
                            width: "110px"
                        }, {
                            field: "workingOfficeStr",
                            title: "工作诊所",
                            width: "120px",
                            attributes: {
                                "class": "cell-left"
                            }
                        }, {
                            field: "showStr",
                            title: "在职状态",
                            width: "80px"
                        }, {
                            field: "user.account",
                            title: "登录账号",
                            width: "100px",
                            attributes: {
                                "class": "provider-account"
                            }
                        }, {
                            field: "user.roleStr",
                            title: "所属角色",
                            width: "90px",
                            attributes: {
                                "class": "cell-left"
                            }
                        }, {
                            template: w.commandTemplate,
                            title: "",
                            width: "160px",
                            attributes: {
                                "class": "cell-command cell-left"
                            }
                        }];
                    return f.departmentDic.load().then(function(i) {
                        var r = i && i.length > 0;
                        r && t.splice(1, 0, {
                            field: "department",
                            title: "科室",
                            width: "80px"
                        });
                        n.resolve(t)
                    }), n.promise
                },
                a, v;
            n.initList = function() {
                n.providers && k().then(function(i) {
                    var u, f, e, o, r, s;
                    p = n.criteria.pageSizeCache ? n.criteria.pageSizeCache : c.getBestRowsForPage(230, 34, 60, 45);
                    u = $(window).height() - 245 - (window.Ares3 ? 30 : 0);
                    f = $(t).find("#providerList");
                    l = f.kendoGrid({
                        dataSource: n.providers,
                        pageable: h.getPageable(p),
                        scrollable: !0,
                        sortable: !0,
                        resizable: !0,
                        selectable: "single",
                        dataBound: b,
                        change: function() {
                            n.criteria.selectedItem = this.dataItem(this.select());
                            n.criteria.page = this.pager.page();
                            var t = _.clone(n.criteria);
                            n.pageStateCache.saveObject(t)
                        },
                        height: u,
                        columns: i
                    }).data("kendoGrid");
                    e = [{
                        field: "name",
                        dir: "asc"
                    }];
                    l.dataSource.sort(e);
                    n.criteria.page && l.dataSource.page(n.criteria.page);
                    n.criteria && n.criteria.selectedItem && (o = l.dataSource, r = o.get(n.criteria.selectedItem.id), r && (s = l.element.find("tbody>tr[data-uid=" + r.uid + "]"), l.select(s)));
                    rt()
                })
            };
            a = function() {
                if (l) {
                    l.dataSource.data(n.providers);
                    var i = t.find(".k-textbox").val();
                    (i - 1) * l.dataSource.pageSize() >= n.providers.length && l.dataSource.page(1)
                } else n.initList()
            };
            v = [{
                text: "修改",
                action: "update",
                icon: "glyphicon-pencil"
            }, {
                text: "删除",
                action: "delete",
                icon: "glyphicon-remove"
            }, {
                text: "修改密码",
                action: "changePwd",
                icon: "icon-lock"
            }];
            o.isAllowed("tenantMgmt.otherOfficeProvider") && v.push({
                text: "取消当前诊所登录授权",
                action: "remove",
                icon: "glyphicon-minus"
            });
            var d = function(t, i, r) {
                    switch (i) {
                        case "update":
                            n.editProvider(r);
                            break;
                        case "delete":
                            n.deleteProvider(r);
                            a();
                            break;
                        case "changePwd":
                            n.changePwd(r)
                    }
                },
                ut = function(n) {
                    var t = r.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<operation-log-list-view><\/operation-log-list-view>",
                        controller: "OperationLogListCtrl",
                        size: "lg",
                        windowClass: "operation-log-dialog",
                        resolve: {
                            host: function() {
                                return {
                                    id: n,
                                    type: "Provider"
                                }
                            }
                        }
                    })
                },
                g = function() {
                    f.officeDic.load().then(function(i) {
                        n.criteria.isWorkingOffice && !n.criteria.selectedOfficeId && (n.criteria.selectedOfficeId = i[0].id, y(i[0].id));
                        var r = n.criteria.isWorkingOffice ? null : "全部诊所";
                        t.find("#officeInput").kendoDropDownList({
                            dataSource: i,
                            dataTextField: "name",
                            dataValueField: "id",
                            optionLabel: r,
                            value: n.criteria.selectedOfficeId || null,
                            change: function(n) {
                                var t = this.dataItem(n.item)[this.options.dataValueField] || 0;
                                y(t)
                            },
                            select: function(t) {
                                n.criteria.selectedOfficeId = this.dataItem(t.item)[this.options.dataValueField] || null;
                                Ares.sensors.trackDropDownEvent("ProviderList", "诊所")
                            }
                        })
                    })
                },
                y = function(i) {
                    i = i || 0;
                    s.getDepartmentByOfficeId(i).success(function(i) {
                        var f = t.find("#departmentInput"),
                            r = i && i.length > 0,
                            u;
                        (n.hasDepartment = r, r) && (n.criteria.department && (u = _.find(i, function(t) {
                            return t.itemName == n.criteria.department
                        }), n.criteria.department = u ? n.criteria.department : null), f.kendoDropDownList({
                            dataSource: i,
                            dataTextField: "itemName",
                            dataValueField: "itemName",
                            optionLabel: "全部科室",
                            value: n.criteria.department || null,
                            select: function(t) {
                                n.criteria.department = this.dataItem(t.item)[this.options.dataValueField] || null;
                                Ares.sensors.trackDropDownEvent("ProviderList", "科室")
                            }
                        }))
                    })
                },
                nt = function() {
                    f.jobDic.load().then(function(i) {
                        var r = t.find("#jobInput"),
                            u = r.kendoDropDownList({
                                dataSource: i,
                                dataTextField: "itemName",
                                dataValueField: "itemName",
                                optionLabel: "全部岗位",
                                value: n.criteria.job || null,
                                select: function(t) {
                                    n.criteria.job = this.dataItem(t.item)[this.options.dataValueField] || null;
                                    Ares.sensors.trackDropDownEvent("ProviderList", "岗位")
                                }
                            })
                    })
                },
                tt = function() {
                    f.roleDic.load().then(function(i) {
                        t.find("#roleInput").kendoDropDownList({
                            dataTextField: "name",
                            dataValueField: "name",
                            dataSource: i,
                            optionLabel: "全部角色",
                            value: n.criteria.roleName || null,
                            select: function(t) {
                                n.criteria.roleName = this.dataItem(t.item)[this.options.dataValueField] || null;
                                Ares.sensors.trackDropDownEvent("ProviderList", "角色")
                            }
                        })
                    })
                },
                it = function() {
                    e.isTenantAdmin || t.find("#titleContainer").find(".provider-office").remove();
                    y();
                    nt();
                    tt()
                },
                rt = function() {
                    var t = $("#providerList").data("kendoGrid"),
                        r = t.pager,
                        i;
                    r.bind("change", function() {
                        n.criteria.selectedItem = null;
                        n.criteria.page = t.pager.page();
                        var i = _.clone(n.criteria);
                        n.pageStateCache.saveObject(i)
                    });
                    i = t.wrapper.children(".k-grid-pager").find("select").data("kendoDropDownList");
                    i.bind("change", function(t) {
                        var r = t.sender.value(),
                            i;
                        n.criteria.pageSizeCache = r;
                        i = _.clone(n.criteria);
                        n.pageStateCache.saveObject(i)
                    })
                };
            (function() {
                n.$watch("providers", function() {
                    a()
                });
                n.$watch("criteria.isWorkingOffice", function() {
                    g()
                });
                n.commands = v;
                n.onCommandClick = d;
                it()
            })()
        }
    }
}]);
tenantModule.directive("roleListView", ["$log", "$modal", "$timeout", "aresDialog", "gridOptionUtil", "kendoUtil", function(n, t, i, r, u, f) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        controller: "RoleListCtrl",
        templateUrl: "/app/tenant/views/role-list-view.html",
        link: function(n, e) {
            var o = null,
                s = 10,
                c = function() {
                    i(function() {
                        n.selectedItem = null;
                        var t = e.find(".k-textbox").val();
                        t > 1 && n.roles && o && n.roles.length != o.dataSource.total() && h();
                        e.find("#roleList table tbody tr").each(function(n) {
                            l(n)
                        })
                    })
                },
                l = function(n) {
                    var t = $(".k-grid-edit", n);
                    t.hide()
                },
                a = function() {
                    return {
                        model: {
                            id: "id",
                            fields: {
                                name: {
                                    type: "string",
                                    validation: {
                                        namevalidation: function(n) {
                                            return n.is('[name="name"]') && n.val() == "" ? (n.attr("data-namevalidation-msg", "名称不能为空"), !1) : !0
                                        }
                                    }
                                },
                                isDefault: {
                                    editable: !1
                                }
                            }
                        }
                    }
                },
                v = function() {
                    return [{
                        field: "name",
                        title: "角色名称",
                        attributes: {
                            "class": "cell-left"
                        },
                        filterable: {
                            cell: {
                                showOperators: !1,
                                operator: "contains",
                                template: function(n) {
                                    n.element.attr("class", "form-control")
                                }
                            }
                        }
                    }, {
                        field: "isDefault",
                        title: "角色类型",
                        width: "100px",
                        template: "# if(isDefault) {#系统角色#} else {#自定义角色#} #",
                        filterable: {
                            cell: {
                                enabled: !1
                            }
                        }
                    }, {
                        command: [{
                            name: "edit",
                            text: {
                                edit: "",
                                update: "",
                                cancel: ""
                            },
                            attributes: {
                                "class": "btn"
                            },
                            imageClass: "glyphicon glyphicon-edit"
                        }, ],
                        width: "80px"
                    }]
                },
                y = function(n, i) {
                    var r = t.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<today-work-config-view><\/today-work-config-view>",
                        controller: "TodayWorkConfigCtrl",
                        size: "md",
                        resolve: {
                            role: function() {
                                return {
                                    roleId: n,
                                    roleName: i
                                }
                            }
                        }
                    })
                },
                p = function() {
                    s = f.getBestRowsForPage(150, 34, 50, 32);
                    var r = new kendo.data.DataSource({
                            data: n.roles,
                            schema: a(),
                            pageSize: s
                        }),
                        h = $(window).height() - 160 - (window.Ares3 ? 25 : 0),
                        t = u.getPageable(s);
                    return t.buttonCount = 3, {
                        dataSource: r,
                        pageable: t,
                        columns: v(),
                        scrollable: !0,
                        selectable: !0,
                        sortable: {
                            mode: "single"
                        },
                        filterable: {
                            mode: "row"
                        },
                        height: h,
                        dataBound: c,
                        save: function(t) {
                            var r = t.model,
                                i = {
                                    id: r.id,
                                    name: r.name
                                };
                            i.id ? n.update(i) : n.add(i)
                        },
                        edit: function(n) {
                            var t, i;
                            c();
                            t = n.container.find(".k-button.k-grid-update");
                            t.hasClass("btn") || (t.addClass("btn"), t.html('<span class="glyphicon glyphicon-ok"><\/span>'), t.attr("title", "保存"));
                            i = n.container.find(".k-button.k-grid-cancel");
                            i.hasClass("btn") || (i.addClass("btn"), i.html('<span class="glyphicon glyphicon-remove"><\/span>'), i.attr("title", "取消"))
                        },
                        cancel: function(n) {
                            i(function() {
                                var i = o.dataSource,
                                    r = i.get(n.model.id),
                                    t = e.find("#roleList tbody>tr[data-uid=" + r.uid + "]");
                                t && l(t)
                            }, 1)
                        },
                        change: function() {
                            var t = this.dataItem(this.select());
                            t.id && n.$apply(function() {
                                n.selectedItem = t ? t : null
                            })
                        },
                        editable: {
                            mode: "inline"
                        }
                    }
                },
                w = function() {
                    o = e.find("#roleList").kendoGrid(p()).data("kendoGrid")
                },
                h = function() {
                    o ? o.dataSource.data(n.roles) : w();
                    n.toBeSelectedRoleId && i(function() {
                        n.toBeSelectedRoleId && (it(n.toBeSelectedRoleId), n.toBeSelectedRoleId = null)
                    }, 20)
                },
                b = function() {
                    var n = e.find(".k-textbox").val();
                    n > 1 && o.dataSource.page(1);
                    o.dataSource.insert(0, {});
                    o.editRow(e.find("#roleList tr:eq(2)"))
                },
                k = function() {
                    if (n.selectedItem && n.selectedItem.uid) {
                        var t = e.find("#roleList").find("tbody>tr[data-uid=" + n.selectedItem.uid + "]");
                        n.selectedItem.isDefault ? r.info("系统提示", "不能修改系统角色！") : o.editRow(t)
                    }
                },
                d = function() {
                    n.selectedItem.isDefault ? r.info("系统提示", "不能删除系统角色！") : n.destroy(n.selectedItem)
                },
                g = function() {
                    var t = n.selectedItem;
                    t && n.copy(t.id)
                },
                nt = function() {
                    var t = n.selectedItem,
                        i, r;
                    t && (i = t.id, r = t.name, y(i, r))
                },
                tt = function() {
                    var t = e.find(".k-textbox").val();
                    (t - 1) * o.dataSource.pageSize() >= n.roles.length - 1 && o.dataSource.page(1)
                },
                it = function(n) {
                    var r = o.dataSource,
                        i = r.get(n),
                        t;
                    i && (t = e.find('#roleList tbody>tr[data-uid="' + i.uid + '"]'), t && o.select(t))
                },
                rt = function() {
                    n.$watch("roles", function() {
                        h()
                    })
                },
                ut = function() {
                    var i = t.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<operation-log-list-view><\/operation-log-list-view>",
                        controller: "OperationLogListCtrl",
                        size: "lg",
                        windowClass: "operation-log-dialog",
                        resolve: {
                            host: function() {
                                return {
                                    id: n.selectedItem.id,
                                    type: "Role"
                                }
                            }
                        }
                    })
                };
            (function() {
                n.addRow = b;
                n.editSelectedRow = k;
                n.removeSelectedRow = d;
                n.refreshGrid = h;
                n.refreshRemoveGridPage = tt;
                n.copyRole = g;
                n.editDashboard = nt;
                n.showRoleChangeLog = ut;
                rt()
            })();
            i(function() {
                Ares.centerModal(e.closest(".modal-dialog"))
            }, 30)
        }
    }
}]);
tenantModule.directive("rolePermissionView", ["$log", "$modal", "$timeout", function(n, t, i) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/tenant/views/role-permission-view.html",
        link: function(n, t) {
            var s = null,
                r = null,
                e = [],
                h = [{
                    id: 1,
                    name: "进销存",
                    code: "SupplychainCenter",
                    parentCode: null,
                    parentId: null,
                    isFolder: !0
                }, {
                    id: 2,
                    name: "采购管理",
                    code: "procurementFolder",
                    parentCode: "SupplychainCenter",
                    parentId: 1,
                    isFolder: !0
                }, {
                    id: 3,
                    name: "库存管理",
                    code: "inventoryFolder",
                    parentCode: "SupplychainCenter",
                    parentId: 1,
                    isFolder: !0
                }, {
                    id: 4,
                    name: "库存单据",
                    code: "inventoryOperationFolder",
                    parentCode: "inventoryFolder",
                    parentId: 3,
                    isFolder: !0
                }, {
                    id: 5,
                    name: "查看采购计划",
                    code: "procurement.procurementViewPlan",
                    parentCode: "procurementFolder",
                    parentId: 2
                }, {
                    id: 7,
                    name: "采购计划中创建订单",
                    code: "procurement.procurementOperation",
                    parentCode: "procurement.procurementViewPlan",
                    parentId: 5
                }, {
                    id: 8,
                    name: "查看购物车",
                    code: "procurement.procurementViewShoppingCart",
                    parentCode: "procurementFolder",
                    parentId: 2
                }, {
                    id: 9,
                    name: "操作购物车",
                    code: "procurement.procurementOperateShoppingCart",
                    parentCode: "procurement.procurementViewShoppingCart",
                    parentId: 8
                }, {
                    id: 16,
                    name: "新增采购需求",
                    code: "procurement.procurementAddProduct",
                    parentCode: "procurement.procurementViewPlan",
                    parentId: 5
                }, {
                    id: 17,
                    name: "查看采购订单",
                    code: "procurement.procurementViewPayOrder",
                    parentCode: "procurementFolder",
                    parentId: 2
                }, {
                    id: 18,
                    name: "订单入库",
                    code: "procurement.procurementInPayOrder",
                    parentCode: "procurement.procurementViewPayOrder",
                    parentId: 17
                }, {
                    id: 19,
                    name: "库存查看",
                    code: "inventoryBrowseFolder",
                    parentCode: "inventoryFolder",
                    parentId: 3,
                    isFolder: !0
                }, {
                    id: 20,
                    name: "当前库存",
                    code: "inventoryBrowse.stockStatus",
                    parentCode: "inventoryBrowseFolder",
                    parentId: 19
                }, {
                    id: 21,
                    name: "库存汇总导出",
                    code: "inventoryBrowse.stockCountSummaryExcel",
                    parentCode: "inventoryBrowse.stockStatus",
                    parentId: 20
                }, {
                    id: 23,
                    name: "库存明细导出",
                    code: "inventoryBrowse.stockDetailExcel",
                    parentCode: "inventoryBrowse.stockStatus",
                    parentId: 20
                }, {
                    id: 24,
                    name: "库存流水导出",
                    code: "inventoryBrowse.stockInOutDetail",
                    parentCode: "inventoryBrowse.stockStatus",
                    parentId: 20
                }, ],
                c = function() {
                    if (n.users) {
                        var i = t.find("#userList");
                        s = i.kendoGrid({
                            dataSource: {
                                data: n.users
                            },
                            height: 605,
                            scrollable: !0,
                            sortable: !0,
                            selectable: !1,
                            columns: [{
                                field: "account",
                                title: "登录账号",
                                width: "100px",
                                attributes: {
                                    "class": "cell-left"
                                }
                            }, {
                                field: "provider.name",
                                title: "姓名",
                                width: "100px"
                            }, ]
                        }).data("kendoGrid")
                    }
                },
                u = function(n, t, i, u) {
                    if (n.dependentCode)
                        if (n.dependentCode == u.code) i = r.dataSource.get(u.id), u = u;
                        else {
                            var f = _.find(t, function(t) {
                                return t.code == n.dependentCode
                            });
                            if (!f) return null;
                            i = r.dataSource.get(f.id);
                            u = f
                        }
                    return {
                        parentNode: i,
                        parentCode: u
                    }
                },
                l = function() {
                    if (n.permissionCategory) {
                        var i = t.find("#permissionList");
                        r = i.kendoTreeView({
                            checkboxes: {
                                checkChildren: !0
                            },
                            check: function(t) {
                                var s = r.dataItem(t.node),
                                    e = _.find(n.permissionCodes, function(n) {
                                        return n.code.toUpperCase() == s.code.toUpperCase()
                                    }),
                                    o, i;
                                e && (o = _.filter(n.permissionCodes, function(n) {
                                    return n.dependentCode == e.code || n.parentCode == e.code
                                }), i = angular.copy(s), angular.forEach(o, function(t) {
                                    var h = angular.copy(e),
                                        s = u(t, o, i, h),
                                        r;
                                    s && (f(s.parentCode, t, s.parentNode), r = _.filter(n.permissionCodes, function(n) {
                                        return n.dependentCode == t.code || n.parentCode == t.code
                                    }), r && angular.forEach(r, function(e) {
                                        var h = angular.copy(t),
                                            s = u(e, r, i, h),
                                            o;
                                        s && (f(s.parentCode, e, s.parentNode), o = _.filter(n.permissionCodes, function(n) {
                                            return n.dependentCode == e.code || n.parentCode == e.code
                                        }), o && angular.forEach(o, function(t) {
                                            var h = angular.copy(e),
                                                s = u(t, o, i, h),
                                                r;
                                            s && (f(s.parentCode, t, s.parentNode), r = _.filter(n.permissionCodes, function(n) {
                                                return n.dependentCode == t.code || n.parentCode == t.code
                                            }), r && angular.forEach(r, function(n) {
                                                var o = angular.copy(t),
                                                    e = u(n, r, i, o);
                                                e && f(e.parentCode, n, e.parentNode)
                                            }))
                                        }))
                                    }))
                                }))
                            },
                            template: kendo.template($("#permission-node-template").html()),
                            dataSource: n.permissionCategory
                        }).data("kendoTreeView");
                        n.isNewOffice && (o("财务中心"), o("绩效中心"));
                        n.isAdminOfficeOpen || o("连锁管理")
                    }
                },
                o = function(n) {
                    var i = 'div.permission-category:contains("' + n + '")';
                    t.find("#permissionList").find(i).each(function() {
                        var i = t.find(this).text();
                        i === n && t.find(this).parent().parent().parent("li.k-item").css("display", "none")
                    })
                },
                f = function(n, i, u) {
                    t.find(".k-item .k-in .permission-code").each(function() {
                        var f = $(this).text(),
                            t;
                        f == i.code && (u.checked || ($(this).parentsUntil(".k-item").find(":input").attr("checked", u.checked), r.dataItem(this).checked = u.checked), _.isArray(n) ? (t = _.find(n, function(n) {
                            return n.code == i.dependentCode
                        }), i.dependentCode && i.dependentCode == t.code && r.enable($(this).parentsUntil(".k-item"), u.checked)) : i.dependentCode && i.dependentCode == n.code && r.enable($(this).parentsUntil(".k-item"), u.checked))
                    })
                },
                a = function() {
                    n.levelValue = n.option != null && (!n.option.isDepartmentLevel && !n.option.isPersonLevel ? "all" : n.option.isDepartmentLevel ? "IsDepartmentLevel" : "IsPersonLevel");
                    t.find("#levelInput").kendoDropDownList({
                        dataSource: [{
                            name: "全部",
                            value: "all"
                        }, {
                            name: "科室级",
                            value: "IsDepartmentLevel"
                        }, {
                            name: "个人级",
                            value: "IsPersonLevel"
                        }],
                        dataTextField: "name",
                        dataValueField: "value",
                        value: n.levelValue,
                        select: function(i) {
                            var r = this.dataItem(i.item.index());
                            r && (n.levelValue = r.value, r.value == "IsDepartmentLevel" ? (t.find("#myPersonLabel").hide(), t.find("#appointmentLabel").hide(), t.find("#departmentLabel").show(), (n.role.name == "网电咨询师" || n.role.name == "网电主管") && t.find("#prohibitEditOtherPatientLabel").show(), t.find("#allLabel").hide(), n.option.isPersonLevel = !1, n.option.isDepartmentLevel = !0, n.option.isMyPatient = !1, n.option.isAppointmentMePatient = !1, n.option.isMyDepartmentPatient = !0) : r.value == "IsPersonLevel" ? (t.find("#myPersonLabel").show(), t.find("#appointmentLabel").show(), t.find("#departmentLabel").hide(), t.find("#prohibitEditOtherPatientLabel").hide(), t.find("#allLabel").hide(), n.option.isPersonLevel = !0, n.option.isDepartmentLevel = !1, n.option.isMyDepartmentPatient = !1, n.$apply(n.option.isMyPatient = !0)) : (t.find("#myPersonLabel").hide(), t.find("#appointmentLabel").hide(), t.find("#departmentLabel").hide(), t.find("#prohibitEditOtherPatientLabel").hide(), t.find("#allLabel").show(), n.option.isPersonLevel = !1, n.option.isDepartmentLevel = !1, n.option.isMyPatient = !1, n.option.isAppointmentMePatient = !1, n.option.isMyDepartmentPatient = !1))
                        }
                    });
                    n.option != null && n.option.isDepartmentLevel ? (t.find("#myPersonLabel").hide(), t.find("#appointmentLabel").hide(), t.find("#departmentLabel").show(), (n.role.name == "网电咨询师" || n.role.name == "网电主管") && t.find("#prohibitEditOtherPatientLabel").show(), t.find("#allLabel").hide()) : n.option == null || n.option.isDepartmentLevel || n.option.isPersonLevel ? (t.find("#myPersonLabel").show(), t.find("#appointmentLabel").show(), t.find("#departmentLabel").hide(), t.find("#prohibitEditOtherPatientLabel").hide(), t.find("#allLabel").hide()) : (t.find("#myPersonLabel").hide(), t.find("#appointmentLabel").hide(), t.find("#departmentLabel").hide(), t.find("#prohibitEditOtherPatientLabel").hide(), t.find("#allLabel").show())
                },
                w = function(n) {
                    var t = this.dataItem(n.node),
                        i = {
                            permissionCode: t.code,
                            allow: t.checked == !0
                        };
                    e = _.reject(e, {
                        permissionCode: t.code
                    });
                    e.push(i)
                },
                v = function() {
                    var t = y();
                    n.option.isOnlyMyPatientEditable = n.levelValue == "IsPersonLevel" ? !0 : (n.role.name == "网电咨询师" || n.role.name == "网电主管") && n.levelValue == "IsDepartmentLevel" ? n.option.isOnlyMyPatientEditable : !1;
                    n.save(t)
                },
                y = function(n) {
                    var t = [],
                        n = r.dataSource.view();
                    return angular.forEach(n, function(n) {
                        for (var i, f, u = n.children.view(), r = 0; r < u.length; r++) i = u[r], i.items && i.items.length > 0 ? angular.forEach(i.items, function(n) {
                            if (n.checked == !0 && n.enabled != !1) {
                                var i = {
                                    permissionCode: n.code,
                                    allow: !0
                                };
                                t.push(i)
                            }
                            n.items && n.items.length > 0 && angular.forEach(n.items, function(n) {
                                if (n.checked == !0 && n.enabled != !1) {
                                    var i = {
                                        permissionCode: n.code,
                                        allow: !0
                                    };
                                    t.push(i)
                                }
                            })
                        }) : i.checked == !0 && i.enabled != !1 && (f = {
                            permissionCode: i.code,
                            allow: !0
                        }, t.push(f))
                    }), t
                },
                p = function() {
                    var n = kendo.observable({
                        isVisible: !0,
                        onSelect: function(n) {
                            var t = $(n.item).children(".k-link").text()
                        }
                    });
                    kendo.bind($("#permissionTabstrip"), n)
                };
            (function() {
                n.permissionDependencyTree = h;
                n.save2 = v;
                p();
                n.$watch("option", function() {
                    a()
                });
                n.$watch("users", function() {
                    c()
                });
                n.$watch("permissionCategory", function() {
                    l()
                });
                i(function() {
                    Ares.centerModal(t.closest(".modal-dialog"))
                }, 5)
            })()
        }
    }
}]);
tenantModule.directive("sharingMgmtView", ["$timeout", "$modal", "enums", "officeSvc", "aresDialog", "loginContext", "appNav", "dataDicSvc", function(n, t, i, r, u, f, e, o) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/sharing-mgmt-view.html",
        link: function(n) {
            var t = i.BaseDataCategory,
                c = [{
                    category: t.ChargeItem,
                    title: "收费项目共享配置",
                    tips: "使用上级共享数据打开后，本诊所收费项目将使用上级群组共享的收费鲜项目，且无法编辑"
                }, {
                    category: t.ChargePayType,
                    title: "收费方式共享配置",
                    tips: "收费方式"
                }],
                e = function() {
                    r.getOfficeBaseDataOption().success(function(t) {
                        t.forEach(function(n) {
                            var t = c.find(function(t) {
                                return t.category === n.category
                            });
                            t && (n.title = t.title, n.tips = t.tips, n.editModeActive = !1, n.isGroup = f.officeType === 1)
                        });
                        n.options = t
                    })
                },
                l = function(n) {
                    r.updateOfficeBaseDataOption(n).success(function() {
                        s();
                        u.info("提示", "基础数据切换成功！")
                    })
                },
                s = function() {
                    n.options = [];
                    e();
                    h()
                },
                h = function() {
                    o.chargeItemDic.clearCache();
                    o.chargeCategoryDic.clearCache();
                    o.chargeSuperCategoryDic.clearCache()
                },
                a = function(n) {
                    n.editModeActive = !0
                },
                v = function(n) {
                    n.editModeActive = !0;
                    l(n)
                },
                y = function(n) {
                    n.editModeActive = !1;
                    s()
                },
                p = function(n) {
                    r.syncBaseData(n.category).success(function() {
                        h();
                        u.info("提示", "数据同步成功")
                    }).error(function() {
                        u.warn("出错啦", "数据同步发生异常")
                    })
                };
            (function() {
                e();
                n.options = [];
                n.onEdit = a;
                n.onSave = v;
                n.onCancel = y;
                n.onSync = p
            })()
        }
    }
}]);
tenantModule.directive("supplyChainConfigView", ["$log", "$timeout", "$modal", "$state", "$q", "$document", "appNav", "aresDialog", "aresNotification", "baiduAreaSvc", "systemitemSvc", "officeSelectorUtil", "enums", "aresConfirmDialog", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/supply-chain-config-view.html",
        controller: "SupplyChainConfigCtrl",
        link: function(n, i) {
            var nt = [{
                    key: "procurementAssistantConfig.historyStatDayCount",
                    min: 0,
                    max: 60
                }, {
                    key: "default",
                    min: 1,
                    max: 1e3
                }],
                lt = function() {
                    var t = yt();
                    if (t !== "") {
                        o.info("提示", t);
                        return
                    }
                    _.each(n.mallNotices, function(n) {
                        var t = $(n.relatedId).data("kendoMultiSelect").value();
                        n.receiverIds = t
                    });
                    n.officeSetting.isInventoryTakeWorkflowEnabled || (n.officeSetting.isInventoryTakeWarehouseRequired = !1);
                    n.officeSetting.defaultInOrderAction = _.map(i.find(".in-warehouse-types").find("input[type=checkbox]:checked"), function(n) {
                        return angular.element(n).attr("data-value")
                    }).join("|");
                    n.officeSetting.defaultOutOrderAction = _.map(i.find(".out-warehouse-types").find("input[type=checkbox]:checked"), function(n) {
                        return angular.element(n).attr("data-value")
                    }).join("|");
                    n.officeSetting.warningWarehouseIds = _.map(i.find(".warning-warehouses").find("input[type=checkbox]:checked"), function(n) {
                        return angular.element(n).attr("data-value")
                    }).join("|");
                    at().then(function() {
                        n.saveConfig().then(function() {
                            n.saveGroupProcurementConfigs().then(function() {
                                s.success("保存成功!");
                                n.isEdit = !1;
                                p(!1)
                            })
                        })
                    })
                },
                at = function() {
                    var t = u.defer(),
                        r = _.any(n.freeTermTypes, function(n) {
                            return n.itemValue == null || n.itemValue == ""
                        }),
                        i;
                    if (r) {
                        s.error("自由项名称不能为空!");
                        t.reject();
                        return
                    }
                    return i = [], angular.forEach(n.freeTermTypes, function(n) {
                        n.isEdit && i.push(n)
                    }), i.length > 0 ? c.addOrEditSystemItems(i).success(function() {
                        angular.forEach(n.freeTermTypes, function(n) {
                            n.isEdit && (n.isEdit = !1)
                        });
                        t.resolve()
                    }).error(function(n) {
                        n.name == "SystemItemNameNotUniqueException" && (s.error("自由项不能重名！"), item.isEmpty = !0, t.reject())
                    }) : t.resolve(), t.promise
                },
                p = function(t) {
                    _.each(n.mallNotices, function(n) {
                        i.find(n.relatedId).data("kendoMultiSelect").enable(t && n.notificationMode >= 2)
                    });
                    i.find("#province").data("kendoDropDownList").enable(t);
                    i.find("#city").data("kendoDropDownList").enable(t);
                    i.find("#district").data("kendoDropDownList").enable(t)
                },
                vt = function() {
                    n.getOfficeSetting().then(function() {
                        ht(!1);
                        st(!1);
                        n.isEdit = !1;
                        n.getFreeTermTypes();
                        p(!1);
                        it();
                        rt();
                        n.getProductCodeManage();
                        n.getSupplyChainConfigs().then(function() {
                            n.getGroupProcurementConfigs();
                            n.groupProcurementCheckAllStatus = {
                                procurement: !1,
                                settlement: !1
                            };
                            t(function() {
                                ct()
                            })
                        })
                    })
                },
                yt = function() {
                    var t = "",
                        i;
                    if (n.officeSetting.isInventoryValidityWarnEnabled && !n.officeSetting.inventoryValidityWarnDayOffset) return $("#inventoryValidityWarnDayOffset").prev("input").focus(), t = "请输入库存有效预警提前天数!";
                    if (n.officeSetting.isInventoryCountWarnEnabled && !n.officeSetting.inventoryCountLowLimit) return $("#inventoryCountLowLimit").prev("input").focus(), t = "请输入库存预警数量!";
                    if (n.officeSetting.isShippingAddressEnabled && (!n.currentReceive.contactName || !n.currentReceive.province || !n.currentReceive.city || !n.currentReceive.district || !n.currentReceive.content || !n.currentReceive.contactPhoneNumber)) return t = "请填写收货地址信息!";
                    if (n.isRoot && n.isGroup && n.isRegularChain && n.isGroupProcurementApplyEnabled && (i = _.find(n.regularOfficeList, function(n) {
                            return !n.isSelfProcurementEnabled && !n.isGroupProcurementEnabled
                        }), i)) return t = "请设置【" + i.name + "】自主采购或总部采购";
                    if (_.find(n.mallNotices, function(n) {
                            if (n.notificationMode === 0) return t = "请设置【" + n.title + "】为下单人或者指定员工", !0;
                            var i = $(n.relatedId).data("kendoMultiSelect").value();
                            if (n.notificationMode >= 2 && i.length === 0) return t = "已设置【" + n.title + "】为指定员工，请至少选择一名员工", !0
                        }), n.officeSetting.inventoryTakeVisibleWarehouse && n.officeSetting.inventoryTakeVisibleWarehouse.visibleMode) switch (n.officeSetting.inventoryTakeVisibleWarehouse.visibleMode) {
                        case a.WarehouseVisibleMode.None:
                            n.officeSetting.inventoryTakeVisibleWarehouse.visibleWarehouses = null;
                            break;
                        case a.WarehouseVisibleMode.AllProvider:
                            n.officeSetting.inventoryTakeVisibleWarehouse.visibleWarehouses[0].warehouseIds.length === 0 && (t = "请至少设置一个领用可见仓库");
                            break;
                        case a.WarehouseVisibleMode.ByDepartment:
                            _.each(n.officeSetting.inventoryTakeVisibleWarehouse.visibleWarehouses, function(n) {
                                return n.department === "" || n.department === "请选择科室" ? (t = "如果选择按科室指定可见仓库，请选择科室", !0) : n.warehouseIds.length === 0 ? (t = "请设置科室【" + n.department + "】的可见仓库", !0) : void 0
                            })
                    }
                    return t
                },
                pt = function(t) {
                    if (n.isEdit) switch (t) {
                        case "isAutoUnpackingEnabled":
                            n.officeSetting.isAutoUnpackingEnabled = !n.officeSetting.isAutoUnpackingEnabled;
                            break;
                        case "isInventoryTakeWorkflowEnabled":
                            n.officeSetting.isInventoryTakeWorkflowEnabled = !n.officeSetting.isInventoryTakeWorkflowEnabled;
                            n.officeSetting.isInventoryTakeWorkflowEnabled || (n.officeSetting.isInventoryTakeWarehouseRequired = !1, n.officeSetting.isInventoryOverflowTakeEnabled = !1, n.officeSetting.inventoryTakeVisibleWarehouse = {
                                visibleMode: a.WarehouseVisibleMode.None,
                                visibleWarehouses: []
                            });
                            break;
                        case "isInventoryTakeWarehouseRequired":
                            n.officeSetting.isInventoryTakeWarehouseRequired = !n.officeSetting.isInventoryTakeWarehouseRequired;
                            n.officeSetting.isInventoryTakeWarehouseRequired && (n.officeSetting.isInventoryOverflowTakeEnabled = !1);
                            break;
                        case "isInventoryValidityWarnEnabled":
                            n.officeSetting.isInventoryValidityWarnEnabled = !n.officeSetting.isInventoryValidityWarnEnabled;
                            break;
                        case "isInventoryCountWarnEnabled":
                            n.officeSetting.isInventoryCountWarnEnabled = !n.officeSetting.isInventoryCountWarnEnabled;
                            break;
                        case "isTakeOutWorkflowEnabled":
                            n.officeSetting.isTakeOutWorkflowEnabled = !n.officeSetting.isTakeOutWorkflowEnabled;
                            n.officeSetting.isTakeOutWorkflowEnabled || (n.officeSetting.isInventoryTakeWorkflowEnabled = !1, n.officeSetting.isInventoryTakeWarehouseRequired = !1);
                            break;
                        case "isInventoryProductSaleEnabled":
                            n.officeSetting.isInventoryProductSaleEnabled = !n.officeSetting.isInventoryProductSaleEnabled;
                            break;
                        case "isInventoryOverflowTakeEnabled":
                            n.officeSetting.isInventoryTakeWorkflowEnabled && (n.officeSetting.isInventoryOverflowTakeEnabled = !n.officeSetting.isInventoryOverflowTakeEnabled, n.officeSetting.isInventoryOverflowTakeEnabled && (n.officeSetting.isInventoryTakeWarehouseRequired = !1));
                            break;
                        case "isShippingAddressEnabled":
                            n.officeSetting.isShippingAddressEnabled = !n.officeSetting.isShippingAddressEnabled;
                            break;
                        case "isGroupInventoryEnabled":
                            n.officeSetting.isGroupInventoryEnabled = !n.officeSetting.isGroupInventoryEnabled;
                            break;
                        case "isInventoryTakePriceByPercentEnabled":
                            n.isInventoryTakePriceByPercentEnabled = !n.isInventoryTakePriceByPercentEnabled;
                            break;
                        case "isGroupProcurementApplyEnabled":
                            n.isGroupProcurementApplyEnabled = !n.isGroupProcurementApplyEnabled;
                            break;
                        case "isStrictWarehouseAdminEnabled":
                            n.officeSetting.isStrictWarehouseAdminEnabled = !n.officeSetting.isStrictWarehouseAdminEnabled;
                            break;
                        case "isAcrossOfficeInventoryTransferEnabled":
                            n.tenantSetting.isAcrossOfficeInventoryTransferEnabled = !n.tenantSetting.isAcrossOfficeInventoryTransferEnabled;
                            break;
                        case "isProcurementPriceLockEnabled":
                            n.officeSetting.isProcurementPriceLockEnabled = !n.officeSetting.isProcurementPriceLockEnabled;
                            break;
                        case "isNeedCheckAgreePrice":
                            n.officeSetting.isNeedCheckAgreePrice = !n.officeSetting.isNeedCheckAgreePrice;
                            break;
                        case "isOfficePreferredDealerEnabled":
                            n.officeSetting.isOfficePreferredDealerEnabled = !n.officeSetting.isOfficePreferredDealerEnabled;
                            break;
                        case "isShowProductByNickNameEnabled":
                            n.officeSetting.isShowProductByNickNameEnabled = !n.officeSetting.isShowProductByNickNameEnabled
                    }
                },
                wt = function() {
                    n.isEdit = !n.isEdit;
                    n.isEdit && p(!0)
                },
                tt = function(n) {
                    var t = _.find(nt, function(t) {
                        return t.key == n
                    });
                    return t || (t = _.find(nt, function(n) {
                        return n.key == "default"
                    })), t
                },
                bt = function(t, i) {
                    var r, u, f;
                    n.isEdit && (r = tt(i), i.indexOf(".") > -1 ? (u = i.split(".")[0], f = i.split(".")[1], t === "reduce" ? n.officeSetting[u][f] > r.min && n.officeSetting[u][f]-- : t === "plus" && n.officeSetting[u][f] < r.max && n.officeSetting[u][f]++) : t === "reduce" ? n.officeSetting[i] > r.min && n.officeSetting[i]-- : t === "plus" && n.officeSetting[i] < r.max && n.officeSetting[i]++)
                },
                kt = function(t) {
                    var i, r, u;
                    _.isNaN(parseInt(n.officeSetting[t])) ? n.officeSetting[t] = 1 : (n.officeSetting[t] = parseInt(n.officeSetting[t]), i = tt(t), t.indexOf(".") > -1 ? (r = t.split(".")[0], u = t.split(".")[1], n.officeSetting[r][u] <= i.min && (n.officeSetting[r][u] = i.min), n.officeSetting[r][u] >= i.max && (n.officeSetting[r][u] = i.max)) : (n.officeSetting[t] <= i.min && (n.officeSetting[t] = i.min), n.officeSetting[t] >= i.max && (n.officeSetting[t] = i.max)))
                },
                it = function() {
                    var f = n.officeSetting.defaultInOrderAction ? n.officeSetting.defaultInOrderAction.split("|") : [],
                        r = i.find(".in-warehouse-types"),
                        u, t;
                    r.find("input").prop("checked", !1);
                    _.each(f, function(n) {
                        r.find("#inWarehouseType" + n).prop("checked", !0)
                    });
                    u = n.officeSetting.defaultOutOrderAction ? n.officeSetting.defaultOutOrderAction.split("|") : [];
                    t = i.find(".out-warehouse-types");
                    t.find("input").prop("checked", !1);
                    _.each(u, function(n) {
                        t.find("#outWarehouseType" + n).prop("checked", !0)
                    })
                },
                dt = function() {
                    ht();
                    st();
                    it();
                    ei()
                },
                gt = function() {
                    var t = n.officeSetting.warningWarehouseIds;
                    return t == "all" ? "all" : t != "" ? t.split("|").map(function(n) {
                        return n
                    }) : []
                },
                rt = function() {
                    n.getWarehouse().then(function() {
                        var r = gt();
                        n.warehouseArrSelected = r;
                        r == "all" && (n.warehouseArrSelected = n.warehouses.map(function(n) {
                            return n.id
                        }));
                        t(function() {
                            var t = i.find(".warning-warehouses");
                            t.find("input").prop("checked", !1);
                            _.each(n.warehouseArrSelected, function(n) {
                                t.find("#warningWarehouse" + n).prop("checked", !0)
                            })
                        });
                        vi()
                    })
                },
                ni = function() {
                    var r = _.any(n.freeTermTypes, function(n) {
                            return n.itemName == "物品自由项1"
                        }),
                        t, i;
                    return r ? (t = _.any(n.freeTermTypes, function(n) {
                        return n.itemName == "物品自由项2"
                    }), !t) ? "物品自由项2" : (i = _.any(n.freeTermTypes, function(n) {
                        return n.itemName == "物品自由项3"
                    }), i ? void 0 : "物品自由项3") : "物品自由项1"
                },
                ti = function() {
                    var t = _.max(n.freeTermTypes, function(n) {
                        return n.displayOrder
                    });
                    return t && t.displayOrder ? t.displayOrder + 1 : 1
                },
                ii = function() {
                    var t = {
                        itemName: ni(),
                        itemType: "物品自由项",
                        itemValue: "",
                        displayOrder: ti(),
                        isEdit: !0,
                        isEmpty: !1
                    };
                    n.freeTermTypes.push(t)
                },
                ri = function(n) {
                    if (n.itemValue == "") {
                        s.error("自由项名称不能为空!");
                        n.isEmpty = !0;
                        return
                    }
                    n.id ? c.updateSystemItem(n).success(function() {
                        n.isEmpty = !1;
                        n.isEdit = !1;
                        return
                    }).error(function(t) {
                        if (t.name == "SystemItemNameNotUniqueException") {
                            s.error("自由项不能重名！");
                            n.isEmpty = !0;
                            return
                        }
                    }) : c.createSystemItem(n).success(function(t) {
                        n.id = t.id;
                        n.isEmpty = !1;
                        n.isEdit = !1;
                        return
                    }).error(function(t) {
                        if (t.name == "SystemItemNameNotUniqueException") {
                            s.error("自由项不能重名！");
                            n.isEmpty = !0;
                            return
                        }
                    })
                },
                ui = function(n) {
                    n.isEdit = !0
                },
                fi = function(t, i) {
                    o.confirm("提示", "您确定删除物品自由项" + t.itemValue + "吗？").then(function() {
                        t.id ? c.deleteFreeItem(t.id).success(function() {
                            n.freeTermTypes.splice(i, 1)
                        }) : n.freeTermTypes.splice(i, 1)
                    })
                },
                e = function(t, i) {
                    var r = u.defer();
                    return n.criteria = {
                        areaCode: t,
                        areaType: i
                    }, h.getSubBaiduAreas(n.criteria).success(function(n) {
                        r.resolve(n)
                    }).error(function(n) {
                        r.reject(n)
                    }), r.promise
                },
                r = function(n, t, r) {
                    var f = i.find(n),
                        u = "",
                        e;
                    switch (n) {
                        case "#province":
                            u = "省";
                            break;
                        case "#city":
                            u = "市";
                            break;
                        case "#district":
                            u = "区"
                    }
                    e = f.kendoDropDownList({
                        dataSource: t,
                        optionLabel: u,
                        dataTextField: "areaName",
                        dataValueField: "areaName",
                        value: r,
                        select: function(n) {
                            r = this.dataItem(n.item)[this.options.dataValueField] || null
                        }
                    }).data("kendoDropDownList")
                },
                w = function(n, t) {
                    var r = 1,
                        i = _.filter(n, {
                            areaName: t
                        });
                    return i && i.length > 0 && (r = i[0].areaCode), r
                },
                ei = function() {
                    n.getInventoryAddressByOfficeId().then(function() {
                        e(1, 1).then(function(i) {
                            var u, f, o;
                            if (n.currentProvinces = i, r("#province", n.currentProvinces, n.currentReceive.province), b("#province", "#city", n.currentProvinces), u = n.currentReceive.province, u == "北京市" || u == "天津市" || u == "上海市" || u == "重庆市" || u == "澳门特别行政区" || u == "香港特别行政区") {
                                n.currentCitys = [{
                                    areaName: u
                                }];
                                n.currentDistricts = [];
                                r("#city", n.currentCitys, n.currentReceive.city);
                                f = w(n.currentProvinces, u);
                                (n.currentReceive.district || n.currentReceive.city && !n.currentReceive.district) && t(e(f, 3).then(function(t) {
                                    n.currentDistricts = t;
                                    r("#district", n.currentDistricts, n.currentReceive.district)
                                }), 200);
                                return
                            }
                            n.currentReceive.province && (o = w(n.currentProvinces, n.currentReceive.province), t(e(o, 2).then(function(i) {
                                n.currentCitys = i;
                                r("#city", n.currentCitys, n.currentReceive.city);
                                b("#city", "#district", i);
                                var u = w(n.currentCitys, n.currentReceive.city);
                                (n.currentReceive.district || n.currentReceive.city && !n.currentReceive.district) && t(e(u, 3).then(function(t) {
                                    n.currentDistricts = t;
                                    r("#district", n.currentDistricts, n.currentReceive.district)
                                }), 200)
                            }), 200))
                        })
                    })
                },
                b = function(u, f, o) {
                    var s = i.find(u),
                        h = i.find(f);
                    s.change(function() {
                        var i, c, l;
                        if (h) {
                            if (i = s.val(), c = f == "#city" ? 2 : 3, !i) {
                                c == 2 && (n.currentCitys = [], n.currentReceive.city = null);
                                t(function() {
                                    n.currentDistricts = [];
                                    n.currentReceive.district = null
                                }, 200);
                                return
                            }
                            if (c == 2 && (n.currentDistricts = []), l = _.filter(o, {
                                    areaName: i
                                }), i == "北京市" || i == "天津市" || i == "上海市" || i == "重庆市" || i == "澳门特别行政区" || i == "香港特别行政区") {
                                if (u == "#province") {
                                    n.currentCitys = [{
                                        areaName: i
                                    }];
                                    n.currentDistricts = [];
                                    r("#city", n.currentCitys, undefined);
                                    r("#district", n.currentDistricts, undefined);
                                    return
                                }
                                l = _.filter(n.currentProvinces, {
                                    areaName: i
                                })
                            }
                            if (l && l.length == 0) return;
                            e(l[0].areaCode, c).then(function(t) {
                                c == 2 ? n.currentCitys = t : n.currentDistricts = t
                            })
                        }
                    })
                },
                ut, ft, k, oi = function() {
                    ut = angular.element(f).find(".page-content");
                    ft = i.find(".config-section-header:first");
                    ut.on("scroll", et)
                },
                et = function() {
                    k && t.cancel(k);
                    k = t(function() {
                        ft.offset().top < 90 ? i.find(".config-top-bar").addClass("fix") : i.find(".config-top-bar").removeClass("fix")
                    }, 200)
                },
                si = function() {
                    i.find('[data-toggle="tooltip"]').tooltip({
                        template: '<div class="tooltip tooltip-info" role="tooltip"><div class="tooltip-arrow"><\/div><div class="tooltip-inner"><\/div><\/div>'
                    })
                },
                ot = function(t, r) {
                    var f = [],
                        u;
                    t.receiverIds !== null && _.each(n.providers, function(n) {
                        t.receiverIds.indexOf(n.userID) > -1 && f.push(n)
                    });
                    u = i.find(t.relatedId);
                    u = (r ? u.kendoMultiSelect({
                        dataTextField: "name",
                        dataValueField: "userID",
                        value: f,
                        dataSource: n.providers
                    }) : u).data("kendoMultiSelect");
                    u.value(f);
                    u.enable(!1)
                },
                st = function(t = true) {
                    n.getProviders().then(function() {
                        setTimeout(function() {
                            _.each(n.mallNotices, function(n) {
                                ot(n, t)
                            })
                        }, 100)
                    })
                },
                hi = function(t, i) {
                    t.notificationMode = (t.mode.createUser ? 1 : 0) + (t.mode.specifiedUser ? 2 : 0);
                    var r = $(i).data("kendoMultiSelect");
                    r.enable(n.isEdit && t.mode.specifiedUser);
                    t.mode.specifiedUser || r.value("")
                },
                ci = function(i) {
                    n.officeSetting.inventoryTakeVisibleWarehouse = {
                        visibleMode: i,
                        visibleWarehouses: [{
                            department: "",
                            index: 0,
                            warehouseIds: []
                        }]
                    };
                    i !== a.WarehouseVisibleMode.None && t(function() {
                        i === a.WarehouseVisibleMode.ByDepartment && d(0, "请选择科室");
                        g(0, [])
                    }, 100)
                },
                li = function(t, i) {
                    n.officeSetting.inventoryTakeVisibleWarehouse.visibleWarehouses.length === 1 ? v.warn({
                        message: "请至少保留一条按科室指定可见仓库配置"
                    }) : t.department !== "请选择科室" ? o.confirm("提示", "您确定要删除科室【" + t.department + "】的可见仓库配置吗？").then(function() {
                        n.officeSetting.inventoryTakeVisibleWarehouse.visibleWarehouses.splice(i, 1)
                    }) : n.officeSetting.inventoryTakeVisibleWarehouse.visibleWarehouses.splice(i, 1)
                },
                ai = function() {
                    var i = "",
                        r;
                    if (_.each(n.officeSetting.inventoryTakeVisibleWarehouse.visibleWarehouses, function(n) {
                            if (n.department === "" || n.department === "请选择科室") {
                                i = "请先选择科室";
                                return
                            }
                            if (n.warehouseIds.length === 0) {
                                i = "请先设置科室【" + n.department + "】的可见仓库";
                                return
                            }
                        }), i !== "") {
                        v.warn({
                            message: i
                        });
                        return
                    }
                    r = n.officeSetting.inventoryTakeVisibleWarehouse.visibleWarehouses.length;
                    n.officeSetting.inventoryTakeVisibleWarehouse.visibleWarehouses.push({
                        department: "",
                        index: r,
                        warehouseIds: []
                    });
                    t(function() {
                        n.officeSetting.inventoryTakeVisibleWarehouse.visibleMode === a.WarehouseVisibleMode.ByDepartment && d(r, "请选择科室");
                        g(r, [])
                    }, 100)
                },
                d = function(t, r) {
                    var u = i.find("#departmentName" + t);
                    u.kendoDropDownList({
                        dataSource: n.departments,
                        optionLabel: name,
                        dataTextField: "itemName",
                        dataValueField: "itemName",
                        value: r,
                        select: function(t) {
                            var i = this.dataItem(t.item)[this.options.dataValueField] || null,
                                r = _.find(n.officeSetting.inventoryTakeVisibleWarehouse.visibleWarehouses, function(n) {
                                    return n.department === i
                                });
                            r && (t.preventDefault(), v.warn({
                                message: "不能重复指定科室"
                            }))
                        }
                    }).data("kendoDropDownList")
                },
                g = function(t, r) {
                    var f = [],
                        u;
                    r !== null && r.length > 0 && _.each(n.warehouses, function(n) {
                        r.indexOf(n.id) > -1 && f.push(n)
                    });
                    u = i.find("#specifiedWarehouse" + t);
                    u = (u[0].options.length === 0 ? u.kendoMultiSelect({
                        dataTextField: "name",
                        dataValueField: "id",
                        value: f,
                        dataSource: n.warehouses,
                        change: function() {
                            var i = this.value();
                            n.officeSetting.inventoryTakeVisibleWarehouse.visibleWarehouses[t].warehouseIds = i
                        }
                    }) : u).data("kendoMultiSelect");
                    u.value(f)
                },
                vi = function() {
                    n.getDepartment().then(function() {
                        n.officeSetting.inventoryTakeVisibleWarehouse && n.officeSetting.inventoryTakeVisibleWarehouse.visibleWarehouses ? t(function() {
                            _.each(n.officeSetting.inventoryTakeVisibleWarehouse.visibleWarehouses, function(n, t) {
                                d(t, n.department);
                                g(t, n.warehouseIds)
                            })
                        }, 100) : n.officeSetting.inventoryTakeVisibleWarehouse = {
                            visibleMode: a.WarehouseVisibleMode.None
                        }
                    })
                },
                l = function(t, i, r) {
                    var u = _.find(n.mallNotices, function(n) {
                        return n.relatedId === i
                    });
                    u ? (t.notificationMode = t.notificationMode === 0 ? 1 : t.notificationMode, u.receiverIds = t.receiverIds, u.mode = {
                        createUser: t.notificationMode !== 2,
                        specifiedUser: t.notificationMode >= 2
                    }) : (t.notificationMode = t.notificationMode === 0 ? 1 : t.notificationMode, t.relatedId = i, t.suffix = i.substr(6), t.title = r, t.mode = {
                        createUser: t.notificationMode !== 2,
                        specifiedUser: t.notificationMode >= 2
                    }, n.mallNotices.push(t))
                },
                ht = function(t = true) {
                    t && (n.mallNotices = []);
                    l(n.officeSetting.procurementDeliveredNotification, "#usersForDelivered", "订单发货通知");
                    l(n.officeSetting.procurementReceivedNotification, "#usersForReceived", "订单到货通知");
                    l(n.officeSetting.procurementPrePaidNotification, "#usersForPrePaid", "付款开始通知");
                    l(n.officeSetting.procurementPaidNotification, "#usersForPaid", "付款完成通知")
                },
                yi = function() {
                    _.each(n.regularOfficeList, function(t) {
                        n.groupProcurementCheckAllStatus.procurement || n.groupProcurementRole.value === "seller" ? (t.isGroupProcurementEnabled = !0, t.isSelfProcurementEnabled = !1) : (t.isGroupProcurementEnabled = !1, t.isSelfProcurementEnabled = !0)
                    })
                },
                pi = function() {
                    _.each(n.regularOfficeList, function(t) {
                        t.isGroupSettlementEnabled = n.groupProcurementCheckAllStatus.settlement
                    })
                },
                y = i.find("#supplychain-office-procurement-table"),
                ct = function() {
                    y.css("max-height", "1000px");
                    y.data("mCustomScrollbarIndex") ? y.mCustomScrollbar("update") : y.mCustomScrollbar({
                        scrollButtons: {
                            enable: !1
                        },
                        autoHideScrollbar: !0,
                        scrollInertia: 150,
                        advanced: {
                            updateOnContentResize: !0
                        }
                    })
                },
                wi = function() {
                    n.groupProcurementRole.value === "seller" && _.each(n.regularOfficeList, function(n) {
                        n.isSelfProcurementEnabled = !1;
                        n.isGroupProcurementEnabled = !0;
                        n.isGroupSettlementEnabled = !0
                    })
                };
            (function() {
                oi();
                si();
                n.getTenantSetting().then(function() {
                    n.getOfficeSetting().then(function() {
                        dt();
                        rt()
                    })
                });
                n.$watch("currentCitys", function() {
                    r("#city", n.currentCitys, undefined);
                    b("#city", "#district", n.currentCitys)
                });
                n.$watch("currentDistricts", function() {
                    r("#district", n.currentDistricts, undefined)
                });
                i.on("$destroy", function() {
                    var n = angular.element(f).find(".page-content");
                    n.off("scroll", et)
                });
                if (n.groupProcurementCheckAllStatus = {
                        procurement: !1,
                        settlement: !1
                    }, window.Ares3) {
                    var t = angular.element(f).find("div[ui-view]");
                    t.css("height", "auto")
                }
                n.changeRequired = pt;
                n.editConfig = wt;
                n.save = lt;
                n.cancel = vt;
                n.initMultiSelect = ot;
                n.opNumberInput = bt;
                n.ensureLegalNumber = kt;
                n.onNewBtnClick = ii;
                n.onSaveNewItem = ri;
                n.editFreeTerm = ui;
                n.deleteFreeTerm = fi;
                n.deleteVisibleWarehouse = li;
                n.addVisibleWarehouse = ai;
                n.onSelectAllRootGroupProcurement = yi;
                n.onSelectAllRootGroupSettlement = pi;
                n.initOfficeTableScrollbar = ct;
                n.changeNotificationMode = hi;
                n.changeVisibleWarehouseMode = ci;
                n.onGroupProcurementRoleChange = wi
            })()
        }
    }
}]);
tenantModule.directive("tenantPermissionConfigView", ["$log", "$timeout", "$modal", "$state", "$q", "$document", "appNav", "aresDialog", "aresNotification", "baiduAreaSvc", "systemitemSvc", "officeSelectorUtil", function(n, t, i, r, u, f, e, o) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/tenant-permission-config-view.html",
        controller: "TenantPermissionConfigCtrl",
        link: function(n) {
            var t = function(t) {
                    n.enableOrthdonticModuleOfficeIds = t && t.length != 0 ? t.map(function(n) {
                        return n.id
                    }) : []
                },
                i = function(t) {
                    n.otherMembershipOfficeIds = t && t.length != 0 ? t.map(function(n) {
                        return n.id
                    }) : []
                },
                r = function(t) {
                    n.autoSplitOfficeIds = t && t.length != 0 ? t.map(function(n) {
                        return n.id
                    }) : []
                },
                u = function(t) {
                    n.thirdPartySpeechCallOfficeIds = t && t.length != 0 ? t.map(function(n) {
                        return n.id
                    }) : []
                },
                f = function(t) {
                    n.diseaseCertificateOfficeIds = t && t.length != 0 ? t.map(function(n) {
                        return n.id
                    }) : []
                },
                e = function(t) {
                    n.enableDeductionChargeOfficeIds = t && t.length != 0 ? t.map(function(n) {
                        return n.id
                    }) : []
                },
                s = function(t) {
                    n.requireProviderFaceRecognitionOfficeIds = t && t.length != 0 ? t.map(function(n) {
                        return n.id
                    }) : []
                },
                h = function(t) {
                    n.enableLDAPOfficeIds = t && t.length != 0 ? t.map(function(n) {
                        return n.id
                    }) : []
                },
                c = function() {
                    n.isEdit = !0
                },
                l = function() {
                    var t;
                    t = n.isMembershipBalanceShareEnabled ? "一旦开启后，会员共享人将可设置积分余额共享，后续若要关闭，所有共享人将不再共享积分余额，请确认是否开启？" : "关闭后已经共享积分余额的所有患者将不再共享积分余额，重新开启后，共享积分余额需要再次手动配置，请确认是否关闭？";
                    o.confirm("操作确认", t).then(null, function() {
                        n.isMembershipBalanceShareEnabled = !n.isMembershipBalanceShareEnabled
                    })
                };
            (function() {
                n.editConfig = c;
                n.onOrthdonticOfficeSelected = t;
                n.onLDAPOfficeSelected = h;
                n.onMembershipOfficeSelected = i;
                n.onChargeDetailOfficeSelected = r;
                n.onSpeechCallOfficeSelected = u;
                n.onDeductionChargeOfficeSelected = e;
                n.onDiseaseCertificateOfficeSelected = f;
                n.onRequiredProviderFaceRecognitionOfficeSelected = s;
                n.onMembershipBalanceShareChange = l
            })()
        }
    }
}]);
tenantModule.directive("userEditView", ["$log", "$timeout", "appNav", "dataDicSvc", "officeSvc", "providerSvc", "loginContext", function(n, t, i, r, u, f, e) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/tenant/views/user-edit-view.html",
        link: function(n, i) {
            var o = function() {
                    var t = {
                        provider: "required",
                        account: {
                            required: !0,
                            minlength: 3
                        },
                        password: {
                            required: !0,
                            minlength: 6,
                            passwordCn: !0
                        },
                        confirmPassword: {
                            required: !0,
                            equalTo: "#password"
                        },
                        roles: {
                            required: !0
                        },
                        loginOffices: "required"
                    };
                    return n.isEdit && (delete t.provider, delete t.account, delete t.password, delete t.confirmPassword), t
                },
                s = function() {
                    var n = o();
                    Ares.validateForm(i.find("#mainForm"), n, {
                        provider: "请选择员工",
                        account: {
                            required: "请输入登录账号",
                            minlength: "登录账号至少3位"
                        },
                        password: {
                            required: "请输入登录密码",
                            minlength: "登录密码至少6位"
                        },
                        confirmPassword: {
                            required: "请输入确认密码",
                            equalTo: "两次输入的密码不一致"
                        },
                        roles: {
                            required: "请选择所属角色"
                        },
                        loginOffices: "请选择可登录诊所"
                    })
                },
                h = function() {
                    r.roleDic.load().then(function(n) {
                        i.find("#roles").kendoMultiSelect({
                            dataTextField: "name",
                            dataValueField: "id",
                            dataSource: n
                        })
                    });
                    r.officeDic.load().then(function(n) {
                        i.find("#loginOffices").kendoMultiSelect({
                            dataTextField: "name",
                            dataValueField: "id",
                            dataSource: n
                        })
                    });
                    n.isEdit || (r.officeDic.load().then(function(n) {
                        i.find("#office").kendoDropDownList({
                            dataSource: n,
                            dataTextField: "name",
                            dataValueField: "id",
                            value: e.officeId,
                            select: function(n) {
                                var t = this.dataItem(n.item)[this.options.dataValueField] || null;
                                t && u(t)
                            }
                        })
                    }), i.find("#provider").kendoDropDownList({
                        dataSource: [],
                        dataTextField: "nameWithJob",
                        dataValueField: "id",
                        select: function(t) {
                            var i = this.dataItem(t.item);
                            i.id && n.$apply(function() {
                                n.user.providerId = i.id
                            })
                        }
                    }))
                },
                c = function() {
                    var t, f;
                    n.isEdit && n.user ? (n.user.roles && (t = _.map(n.user.roles, function(n) {
                        return n.id
                    }), i.find("#roles").data("kendoMultiSelect").value(t)), n.user.loginOffices && (f = _.map(n.user.loginOffices, function(n) {
                        return n.id
                    }), i.find("#loginOffices").data("kendoMultiSelect").value(f)), n.user.provider && (n.user.officeName = r.officeDic.getItemSync(n.user.provider.officeId).name)) : n.isEdit || (u(e.officeId), i.find("#loginOffices").data("kendoMultiSelect").value([e.officeId]))
                },
                u = function(n) {
                    f.getProvidersWithoutAccount(n).success(function(n) {
                        angular.forEach(n, function(n) {
                            n.nameWithJob = n.name + "【" + n.job + "】"
                        });
                        var t = i.find("#provider").data("kendoDropDownList");
                        t.dataSource.data(n)
                    })
                },
                l = function() {
                    var r = i.find("#roles").data("kendoMultiSelect").value(),
                        u, t, f;
                    r && r.length > 0 ? (u = _.map(r, function(n) {
                        return {
                            id: n
                        }
                    }), n.user.roles = u) : n.user.roles = null;
                    t = i.find("#loginOffices").data("kendoMultiSelect").value();
                    t && t.length > 0 ? (f = _.map(t, function(n) {
                        return {
                            id: n
                        }
                    }), n.user.loginOffices = f) : n.user.loginOffices = null;
                    n.isEdit || (n.user.providerId = i.find("#provider").data("kendoDropDownList").value())
                },
                a = function() {
                    l();
                    i.find("#mainForm").valid() && n.save()
                };
            (function() {
                n.save2 = a;
                s();
                h();
                n.$watch("user", function() {
                    c()
                })
            })();
            t(function() {
                Ares.centerModal(i.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
tenantModule.directive("userListView", ["$log", "$timeout", "appNav", function(n, t) {
    "use strict";
    return {
        restrict: "E",
        controller: "UserListCtrl",
        templateUrl: "/app/tenant/views/user-list-view.html",
        link: function(n, i) {
            var r = null,
                u = function() {
                    if (n.users) {
                        var u = $(i).find("#userList");
                        r = u.kendoGrid({
                            dataSource: {
                                data: n.users
                            },
                            scrollable: !1,
                            sortable: !0,
                            selectable: "single",
                            change: function() {
                                var i = this.dataItem(this.select());
                                t(function() {
                                    n.selectedItem = i ? i : null
                                })
                            },
                            columns: [{
                                field: "name",
                                title: "姓名",
                                width: "60px",
                                attributes: {
                                    "class": "cell-left"
                                }
                            }, {
                                field: "job",
                                title: "岗位",
                                width: "60px",
                                attributes: {
                                    "class": "cell-left"
                                }
                            }, {
                                field: "account",
                                title: "登录账号",
                                width: "40px",
                                attributes: {
                                    "class": "cell-left"
                                }
                            }, {
                                field: "roleStr",
                                title: "角色",
                                width: "200px",
                                attributes: {
                                    "class": "cell-left"
                                }
                            }, {
                                field: "officeStr",
                                title: "可登录诊所",
                                width: "200px",
                                attributes: {
                                    "class": "cell-left"
                                }
                            }, {
                                field: "stateStr",
                                title: "状态",
                                width: "40px"
                            }, ]
                        }).data("kendoGrid")
                    }
                },
                f = function() {
                    var f, t, e;
                    r ? (r.dataSource.data(n.users), n.selectedItem && (f = r.dataSource, t = f.get(n.selectedItem.id), t && (e = $(i).find("#userList").find("tbody>tr[data-uid=" + t.uid + "]"), r.select(e)), n.selectedItem = t)) : u()
                };
            (function() {
                n.$watch("users", function() {
                    f()
                })
            })()
        }
    }
}]);
tenantModule.directive("weixinUploadView", ["$log", "$timeout", "$state", "officeSvc", function() {
    return {
        restrict: "A",
        scope: {
            add: "&",
            send: "&",
            start: "&",
            stop: "&",
            fail: "&",
            destroy: "&",
            done: "&",
            uploadprogress: "&"
        },
        link: function(n, t) {
            function i(n, t) {
                var i = {
                    dataType: "json",
                    type: "POST",
                    sequentialUploads: !0,
                    autoUpload: !0,
                    multipart: !1
                };
                n.add && (i.add = function(t, i) {
                    n.$apply(function() {
                        n.add({
                            e: t,
                            data: i
                        })
                    })
                });
                n.fail && (i.fail = function(t, i) {
                    n.$apply(function() {
                        n.fail({
                            e: t,
                            data: i
                        })
                    })
                });
                n.done && (i.done = function(t, i) {
                    n.$apply(function() {
                        n.done({
                            e: t,
                            data: i
                        })
                    })
                });
                n.uploadprogress && (i.progress = function(t, i) {
                    n.$apply(function() {
                        n.uploadprogress({
                            e: t,
                            data: i
                        })
                    })
                });
                t.fileupload(i)
            }
            var r = function() {
                    $("#weixinKey").on("click", u)
                },
                u = function() {
                    n.$parent.$parent.uploadType = "weixinkey";
                    $("#weixinKeyUploadPanel").click()
                };
            (function() {
                r()
            })(i(n, t))
        }
    }
}]);
tenantModule.directive("workflowManagementView", ["$log", "$timeout", "$modal", "$state", "moduleOptionProvider", "aresDialog", "aresNotification", function(n, t, i, r, u, f, e) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/workflow-management-view.html",
        controller: "WorkflowManagementCtrl",
        link: function(n, r) {
            var a = function() {
                    var t = tt();
                    if (t !== "") {
                        f.info("提示", t);
                        return
                    }
                    n.checkCanConvetToShortenUrl(n.officeSetting.apptSurveyUrl).then(function() {
                        n.saveConfig()
                    }, function() {
                        f.info("提示", "该满意度调查地址不能缩短为短地址");
                        return
                    })
                },
                v = function() {
                    n.isEdit = !n.isEdit;
                    r.find("#shortMessageTemplate").removeAttr("disabled");
                    r.find("#apptSurveyTemplate").removeAttr("disabled");
                    n.chargeItemProviderDropdownlist.enable(!0);
                    s()
                },
                y = function() {
                    n.initData().then(function() {
                        n.isEdit = !1
                    });
                    n.chargeItemProviderDropdownlist.enable(!1)
                },
                p = function() {
                    var i = n.shortMessageTemplates,
                        u, r;
                    if (i.length == n.patientTypes.length) {
                        f.info("提示", "添加的特殊模版不能大于患者类别个数!");
                        return
                    }
                    u = {
                        name: "删除",
                        id: "0",
                        shortMessageTemplate: {
                            content: ""
                        }
                    };
                    i.splice(i.length, 0, u);
                    r = i.length - 1;
                    t(function() {
                        h("patientType" + r);
                        o("shortMessageTemplate" + r)
                    })
                },
                w = function(t) {
                    n.shortMessageTemplates.splice(t, 1);
                    n.isChangeApp = !0
                },
                b = function() {
                    r.find("#sealing-config").kendoValidator({
                        rules: {
                            datepicker: function(n) {
                                return n.data("kendoTimePicker").value()
                            }
                        },
                        messages: {
                            datepicker: "请输入合法的时间!"
                        }
                    }).data("kendoValidator")
                },
                o = function(t, i) {
                    var u = i ? n.allShortMessageTemplates : n.appointmentTemplates;
                    r.find("#" + t).kendoDropDownList({
                        optionLabel: "--请选择--",
                        dataTextField: "name",
                        dataValueField: "id",
                        dataSource: u,
                        change: function(r, u) {
                            if (!i) {
                                n.isChangeApp = !0;
                                var u = t.substr(20),
                                    f = this.dataItem(r.item);
                                u ? n.shortMessageTemplates[u].shortMessageTemplate = f : n.defaultTemplate.shortMessageTemplate = f
                            }
                        }
                    })
                },
                h = function(t) {
                    r.find("#" + t).kendoDropDownList({
                        optionLabel: "-请选择-",
                        dataTextField: "itemName",
                        dataValueField: "id",
                        dataSource: n.patientTypes,
                        change: function() {
                            n.isChangeApp = !0
                        }
                    })
                },
                k = function() {
                    var t = function() {
                        var r = _.any(n.chargeItemFreeFields, function(n) {
                                return n.itemName == "收费项目自由项1"
                            }),
                            t, i;
                        return r ? (t = _.any(n.chargeItemFreeFields, function(n) {
                            return n.itemName == "收费项目自由项2"
                        }), !t) ? "收费项目自由项2" : (i = _.any(n.chargeItemFreeFields, function(n) {
                            return n.itemName == "收费项目自由项3"
                        }), i ? void 0 : "收费项目自由项3") : "收费项目自由项1"
                    };
                    n.onDeleteFreeField = function(t) {
                        var i = n.chargeItemFreeFields[t];
                        f.confirm("提示", "您确定删除物品自由项" + i.itemValue + "吗？<br/>                                当点击保存时将删除所有与这个自由项相关的配置和选项").then(function() {
                            n.chargeItemFreeFields.splice(t, 1);
                            n.chargeItemFreeFields.forEach(function(n, t) {
                                n.displayOrder = t + 1
                            })
                        })
                    };
                    n.onAddFreeField = function() {
                        var i = _.max(n.chargeItemFreeFields, function(n) {
                                return n.displayOrder
                            }),
                            r = i && i.displayOrder ? i.displayOrder + 1 : 1;
                        n.chargeItemFreeFields.push({
                            itemName: t(),
                            itemType: "收费项目自由项",
                            itemValue: "",
                            displayOrder: r,
                            isEdit: !0,
                            isEmpty: !1
                        })
                    }
                },
                d = function() {
                    n.officeSetting.isSendWeixinApptSurvey && n.officeSetting.isSendMessageApptSurvey || (n.officeSetting.isOnlyWeixinApptSurvey = !1)
                },
                g = function() {
                    var t = n.defaultTemplate,
                        i = r.find("#shortMessageTemplate"),
                        u = i.data("kendoDropDownList"),
                        f, e;
                    t ? i.length > 0 && i.val() != t.shortMessageTemplate.name && u && u.select(function(n) {
                        return n.name === t.shortMessageTemplate.name
                    }) : (f = _.find(n.appointmentTemplates, function(n) {
                        return n.name == "预约提醒"
                    }), n.defaultTemplate = {
                        shortMessageTemplate: f
                    }, u.select(function(n) {
                        return n.name == f.name
                    }));
                    angular.forEach(n.shortMessageTemplates, function(n, t) {
                        var i = r.find("#patientType" + t).data("kendoDropDownList"),
                            u = r.find("#shortMessageTemplate" + t).data("kendoDropDownList");
                        i && i.select(function(t) {
                            return t.itemName === n.patientType
                        });
                        u && u.select(function(t) {
                            return t.name === n.shortMessageTemplate.name
                        })
                    });
                    e = r.find("#apptSurveyTemplate").data("kendoDropDownList");
                    e && e.value(n.officeSetting.apptSurveyTemplateId)
                },
                nt = function() {
                    if (n.chargeItemFreeFields.length === 0) return "";
                    var t = n.chargeItemFreeFields.map(function(n) {
                        return n.itemValue
                    }).filter(function(n) {
                        return !!n
                    });
                    return t.length != n.chargeItemFreeFields.length ? "自由项名称不能为空!" : _.uniq(t).length != t.length ? "自由项不能重名！" : ""
                },
                tt = function() {
                    var t = "",
                        f, e, o, c, i, u, s, l, a, h;
                    if (!n.sealingTimePicker) return r.find("startDatePicker").focus(), "请输入正确的每日封账时间!";
                    if (n.officeSetting.isReminderServiceEnabled) {
                        if (!n.officeSetting.reminderDayOffset) return $("#reminderDayOffset").prev("input").focus(), "请输入预约提醒服务提前天数!";
                        if (!n.officeSetting.reminderStartTime) return $("#reminderStartTime").focus(), "请输入预约提醒服务的开始时间!"
                    }
                    if (n.officeSetting.preoperativeRemindConfig.isEnabled) {
                        if (!n.officeSetting.preoperativeRemindConfig.dayOffset) return $("#preoperativeRemindConfig_dayOffset").prev("input").focus(), "请输入术前提醒服务提前天数!";
                        if (!n.officeSetting.preoperativeRemindConfig.startTime) return $("#preoperativeRemindConfig_startTime").focus(), "请输入术前提醒服务的开始时间!";
                        if (!/^\d{2}:\d{2}$/.test(n.officeSetting.preoperativeRemindConfig.startTime) && !/^\d{2}:\d{2}:\d{2}$/.test(n.officeSetting.preoperativeRemindConfig.startTime)) return $("#preoperativeRemindConfig_startTime").focus(), "术前提醒服务的开始时间格式不正确!"
                    }
                    if (n.officeSetting.isInventoryValidityWarnEnabled && !n.officeSetting.inventoryValidityWarnDayOffset) return $("#inventoryValidityWarnDayOffset").prev("input").focus(), "请输入库存有效预警提前天数!";
                    if (n.officeSetting.isApptSurveyEnabled)
                        if (n.officeSetting.isSendMessageApptSurvey) {
                            if (!n.officeSetting.apptSurveyTemplateId) return $("#apptSurveyTemplate").focus(), "请选择满意度回访短信模板!"
                        } else if ((console.log(n.isWxClinic), !n.isWxClinic) || !n.officeSetting.isSendWeixinApptSurvey) return "请选择发送渠道";
                    if (n.systemConfigs.isChargeItemProviderUnique) {
                        if (f = n.chargeItemProviderDropdownlist.value(), f.length <= 1) return "收费项目人员唯一范围需要至少两个角色";
                        n.systemConfigs.chargeItemProviderRange = f.join(",")
                    }
                    if (e = r.find("#shortMessageTemplate").val(), e == "") t = "请选择默认模版!";
                    else
                        for (n.appTemplates = [], o = [], c = {
                                patientType: "",
                                shortMessageTemplateId: e,
                                isDefault: !0,
                                officeId: 0
                            }, n.appTemplates.push(c), i = 0; i < n.shortMessageTemplates.length; i++) {
                            if (u = r.find("#patientType" + i).val(), u == "") {
                                t = "请选择患者类型!";
                                break
                            }
                            if (s = r.find("#shortMessageTemplate" + i).val(), s == "") {
                                t = "请选择患预约模版!";
                                break
                            }
                            if (o.indexOf(u) > -1) {
                                t = "患者类型重复,请重新选择!";
                                break
                            } else o.push(u), l = r.find("#patientType" + i).data("kendoDropDownList").text(), a = {
                                patientType: l,
                                shortMessageTemplateId: s,
                                isDefault: !1,
                                officeId: 0
                            }, n.appTemplates.push(a)
                        }
                    return t || (t = ht()), t || (t = at()), t || (t = nt()), n.officeSetting.shortMessageSignature && (h = n.officeSetting.shortMessageSignature.length, (h < 2 || h > 6) && (t = "短信签名必须大于2且小于6个字符!")), t
                },
                s = function(i) {
                    b();
                    o("shortMessageTemplate");
                    o("apptSurveyTemplate", !0);
                    n.initChargeItemProviderDropdownlist();
                    t(function() {
                        angular.forEach(n.shortMessageTemplates, function(n, t) {
                            h("patientType" + t);
                            o("shortMessageTemplate" + t)
                        });
                        angular.forEach(n.specialCheckInChargeItemTemplates, function(n, t) {
                            c("checkInType" + t)
                        });
                        angular.forEach(n.discountLimitSettings, function(n, t) {
                            n.scope == 2 && l("discountLimitRoleType" + t)
                        });
                        k();
                        i && i()
                    }, 10)
                },
                it = function() {
                    var t, i;
                    n.chargeItemProviderDropdownlist || (n.chargeItemProviderDropdownlist = r.find("#chargeItemProviders").kendoMultiSelect({
                        dataSource: ["医生", "护士", "咨询师", "销售人员"]
                    }).data("kendoMultiSelect"));
                    t = n.systemConfigs.chargeItemProviderRange;
                    t && t.length > 0 && (i = t.split(","), n.chargeItemProviderDropdownlist.value(i))
                },
                rt = function() {
                    n.isEdit = !1;
                    r.find("#shortMessageTemplate").attr("disabled", "disabled");
                    r.find("#apptSurveyTemplate").attr("disabled", "disabled");
                    n.chargeItemProviderDropdownlist.enable(!1);
                    s()
                },
                ut = function() {
                    s(g)
                },
                ft = function(t) {
                    var i = t.sender;
                    /^\d{2}:\d{2}$/.test(n.officeSetting.reminderStartTime) || (n.officeSetting.reminderStartTime = "10:00", i.value("10:00"))
                },
                et = function(t) {
                    var i = t.sender;
                    /^\d{2}:\d{2}$/.test(n.officeSetting.preoperativeRemindConfig.startTime) || (n.officeSetting.preoperativeRemindConfig.startTime = "10:00", i.value("10:00"))
                },
                ot = function() {
                    return "/app/tenant/views/ali-upload-view.html"
                },
                st = function() {
                    return "/app/tenant/views/weixin-upload-view.html"
                },
                c = function(t) {
                    var i = r.find("#" + t);
                    i.kendoDropDownList({
                        optionLabel: "-请选择-",
                        dataTextField: "itemName",
                        dataValueField: "itemName",
                        dataSource: n.checkInTypes,
                        change: function() {
                            n.isCheckInChanged = !0
                        }
                    })
                },
                ht = function() {
                    if (n.officeSetting.isCheckInChargeEnabled) {
                        var i = n.defaultCheckInChargeItemTemplate,
                            t = n.specialCheckInChargeItemTemplates;
                        if (!i.chargeItems || !i.chargeItems.length) return "请选择挂号默认收费项！";
                        if (t.length > 0) {
                            if (_.any(t, function(n) {
                                    return !n.checkInType || n.checkInType == ""
                                })) return "请选择特殊挂号类型！";
                            if (_.any(t, function(n) {
                                    return !n.chargeItems || !n.chargeItems.length
                                })) return "请选择特殊挂号类型收费项！";
                            if (_.uniq(_.pluck(t, "checkInType")).length < t.length) return "挂号类型重复，请重新选择！"
                        }
                    }
                    return ""
                },
                ct = function() {
                    var i = n.specialCheckInChargeItemTemplates,
                        r, u;
                    if (i.length == n.checkInTypes.length) {
                        f.info("提示", "添加的特殊模版不能大于挂号类型个数!");
                        return
                    }
                    r = {
                        chargeItemNames: n.getDisplayNames([]),
                        chargeItems: [],
                        checkInType: "",
                        isDefault: !1
                    };
                    i.splice(i.length, 0, r);
                    u = i.length - 1;
                    t(function() {
                        c("checkInType" + u)
                    })
                },
                lt = function(t) {
                    n.specialCheckInChargeItemTemplates.splice(t, 1)
                },
                l = function(t) {
                    var i = r.find("#" + t);
                    i.kendoDropDownList({
                        optionLabel: "-请选择-",
                        dataTextField: "name",
                        dataValueField: "id",
                        dataSource: n.roleTypes,
                        change: function() {
                            n.isDiscountLimitChanged = !0
                        }
                    })
                },
                at = function() {
                    var t, i;
                    if (n.systemConfigs.allowMinDiscount && (t = n.discountLimitSettings, t.length > 0)) {
                        if (_.any(t, function(n) {
                                return !n.referenceId || n.referenceId <= 0
                            })) return "请给折扣下限选择角色！";
                        if (i = _.map(t, function(n) {
                                return n.referenceId.toString()
                            }), _.uniq(i).length < t.length) return "折扣下限中角色重复！"
                    }
                    return ""
                },
                vt = function() {
                    var i = n.discountLimitSettings,
                        r, u;
                    if (i.length == n.roleTypes.length) {
                        f.info("提示", "折扣下限添加的特殊规则不能大于角色类型个数!");
                        return
                    }
                    r = {
                        id: 0,
                        scope: 2,
                        referenceId: -1,
                        orderLowerLimit: 0,
                        detailLowerLimit: 0
                    };
                    i.splice(i.length, 0, r);
                    n.isDiscountLimitChanged = !0;
                    u = i.length - 1;
                    t(function() {
                        l("discountLimitRoleType" + u)
                    })
                },
                yt = function(t) {
                    n.discountLimitSettings.splice(t, 1);
                    n.isDiscountLimitChanged = !0
                },
                pt = function(t) {
                    var r = angular.copy(t.chargeItems),
                        u = i.open({
                            animation: !0,
                            backdrop: "static",
                            template: "<charge-item-selector-plus-view><\/charge-item-selector-plus-view>",
                            controller: "ChargeItemSelectorPlusCtrl",
                            windowClass: "membership-discountplan-detail-dialog",
                            resolve: {
                                host: function() {
                                    return {
                                        existChargeItemList: r,
                                        selectedLengthLimitMethod: function(n) {
                                            return n.length > 5 ? (e.error("挂号收费项目数量不能大于5个。"), !1) : !0
                                        }
                                    }
                                }
                            }
                        });
                    u.result.then(function(i) {
                        i && i.length != 0 && (angular.forEach(i, function(n) {
                            n.condType = "chargeItem"
                        }), t.chargeItems = i, t.chargeItemNames = n.getDisplayNames(t.chargeItems), n.isCheckInChanged = !0)
                    })
                },
                wt = function() {
                    n.systemConfigs.isEnableFinanceDay || (n.officeSetting.isHistoryFinanceDayDeductionEnabled = !0)
                },
                bt = function() {
                    n.initFinanceDayInfo(n.systemConfigs.financeDay)
                },
                kt = function() {
                    n.officeSetting.isHistoryFinanceDayDeductionEnabled = !n.officeSetting.isHistoryFinanceDayDeductionEnabled
                },
                dt = function() {
                    n.officeSetting.isGiftCertificateInAdvanceEndabled && f.confirm("提示", "保存后将无法切换回销售计入，确定切换？").then(null, function() {
                        n.officeSetting.isGiftCertificateInAdvanceEndabled = !1
                    })
                },
                gt = function() {
                    !n.officeSetting.isChargeItemPriceUpdatable && n.officeSetting.isYibaoItemPriceUpdatable && (n.officeSetting.isYibaoItemPriceUpdatable = !1)
                },
                ni = function() {
                    n.officeSetting.isAppointmentConsultAppendable = !1
                };
            (function() {
                n.onSwitchFinanceDay = wt;
                n.onChangeFinanceDay = bt;
                n.getAliUploadUrl = ot;
                n.getWeixinUploadUrl = st;
                n.reminderStartTimeChange = ft;
                n.onChangeFinanceDayDeductionLimit = kt;
                n.preoperativeRemindStartTimeChange = et;
                n.onAddRow = p;
                n.onDelRow = w;
                n.editConfig = v;
                n.save = a;
                n.cancel = y;
                n.saveOver = rt;
                n.initTimeOut = ut;
                n.showItemsDlg = pt;
                n.onAddCheckInTemplate = ct;
                n.onDelCheckInTemplate = lt;
                n.onAddDiscountLimitSetting = vt;
                n.onDelDiscountLimitSetting = yt;
                n.sendWeixinApptSurveyChange = d;
                n.initChargeItemProviderDropdownlist = it;
                n.chargeItemProviderDropdownlist = null;
                n.onChangeGiftCertificateInAdvance = dt;
                n.resetIsAppointmentConsultAppendable = ni;
                n.isGiftCertificateBillingEnabled = u.isGiftCertificateBillingEnabled();
                n.onChangeAllowUpdatePrice = gt
            })()
        }
    }
}]);
tenantModule.directive("handoverChargeDeductionView", ["$log", "$window", "$modal", "$timeout", "$q", "kendoUtil", "gridOptionUtil", "loginContext", "aresDialog", "appNav", "aresModalShelf", "handOverSvc", "aresSlidePanel", function(n, t, i, r, u, f, e, o, s, h, c, l, a) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/handover/handover-charge-deduction-view.html",
        controller: "HandoverChargeDeductionCtrl",
        link: function(n, e) {
            var h = null,
                c = null,
                ht = null,
                k = null,
                d = null,
                g = null,
                oi = Ares.kendoGridUtil(t, n),
                nt = [],
                tt = [],
                y = [],
                it = [],
                p = [{
                    template: "<div class='double-line-text' title='#: patientId #'><a data-patient-id ='#: patientId #'>#: patientName #<\/a><span class='badge patient-indicator patient-indicator-overdue' title = '#: (overDue > 0 ? ('欠款:' + overDue) : '') #'>#: (overDue > 0 ? '欠' : '') #<\/span><\/div>",
                    field: "patientName",
                    title: "<span class='first-column-text'>姓名<\/span>",
                    headerAttributes: {
                        "class": "cell-left",
                        style: "min-width:150px"
                    },
                    attributes: {
                        "class": "cell-left"
                    },
                    width: "150px"
                }, {
                    title: "病历号",
                    field: "privateId",
                    width: "120px"
                }, {
                    title: "性别",
                    field: "sexStr",
                    width: "85px"
                }, {
                    title: "年龄",
                    field: "ageStr",
                    width: "85px"
                }, {
                    title: "开单日期",
                    field: "payDateTimeStr",
                    width: "150px"
                }, {
                    title: "咨询师",
                    field: "consultantName",
                    width: "85px"
                }, {
                    title: "项目名称",
                    field: "chargeItemName",
                    width: "200px"
                }, {
                    title: "总步骤数量",
                    field: "stepCount",
                    width: "150px"
                }, {
                    title: "待执行步骤数量",
                    field: "pendingStepCount",
                    width: "150px"
                }, {
                    title: "待执行步骤",
                    field: "stepName",
                    width: "120px"
                }, {
                    title: "执行医生",
                    field: "executionDoctorName",
                    width: "120px"
                }],
                w;
            n.isGroup && p.splice(0, 0, {
                title: "所属机构",
                field: "officeName",
                width: "85px"
            });
            w = f.CommonColumnsNotINHeader.checkboxColumn;
            w.locked = !0;
            p.splice(0, 0, w);
            var rt = null,
                l, v = function(i) {
                    n.refreshListData(i).then(function(i) {
                        var u, o;
                        rt = angular.copy(p);
                        u = e.find("#chargeDeductionGrid");
                        u.html("");
                        o = t.innerHeight - 260 - (window.Ares3 ? 50 : 0);
                        n.chargeDeductionList = i.items;
                        r(function() {
                            l = u.kendoGrid({
                                excel: {
                                    allPages: !0
                                },
                                dataSource: {
                                    data: i.items
                                },
                                height: o,
                                model: {
                                    id: "id"
                                },
                                columns: rt,
                                sortable: !1,
                                resizable: !0,
                                reorderable: !0,
                                dataBound: function(t) {
                                    Ares.DockGridColMenuPos(t.sender);
                                    $(e).find("#chargeDeductionGrid tbody tr td a").each(function() {
                                        $(this).bind("click", function(n) {
                                            var t = $(this).attr("data-patient-id");
                                            t && ct(t, n)
                                        })
                                    });
                                    $(e).find("#chargeDeductionGrid table tbody tr td .commonColumns_sub_checkbox").each(function() {
                                        $(this).bind("click", function(t) {
                                            var i = f.selectSingleRow(l, "chargeDeductionGrid", n.pageData.items.length, this, t);
                                            ut(i)
                                        })
                                    })
                                }
                            }).data("kendoGrid")
                        })
                    })
                },
                ct = function(t) {
                    var i = a.open("<customer-details-view><\/customer-details-view>", "CustomerDetailsCtrl", {
                        host: function() {
                            return {
                                patientId: t,
                                isHideBtn: !0
                            }
                        }
                    }, n);
                    i.result.then(function() {})
                },
                ut = function(t) {
                    n.selectedRows = t;
                    r(function() {
                        n.selectTotalCount = n.selectedRows == n.pageData.totalCount
                    })
                },
                si = function(t) {
                    n.showColumns = t
                },
                hi = function() {
                    $(e).find("#chargeDeductionGrid table tbody tr td .commonColumns_sub_checkbox").each(function() {
                        $(this).bind("click", function(t) {
                            var i = f.selectSingleRow(l, "chargeDeductionGrid", n.pageData.items.length, this, t);
                            ut(i)
                        })
                    })
                },
                lt = function() {
                    var i = f.getCustomSelectedData(l),
                        t = [];
                    return n.isAssignedFlag = !1, i.forEach(function(n) {
                        t.push({
                            chargeOrderid: n.chargeOrderId,
                            groupIndex: n.groupIndex,
                            itemGroupIndex: n.itemGroupIndex
                        })
                    }), t = _.uniq(t)
                },
                at = function(t) {
                    var i = e.find("#chargeDeductionGrid"),
                        r = f.selectAllRow(l, "chargeDeductionGrid", t);
                    n.selectedRows = t ? n.pageData.totalCount : 0
                },
                vt = function(t) {
                    n.criteria.pageIndex = t;
                    var i = n.validateData();
                    i && v()
                },
                yt = function(t) {
                    n.criteria.pageSize = t;
                    var i = n.validateData();
                    i && v()
                },
                pt = function() {
                    dt();
                    gt();
                    ni();
                    ti();
                    b().then(function() {
                        ft(n.selectedOfficeIds);
                        v(!0)
                    })
                },
                b = function(t) {
                    var i = u.defer();
                    return n.queryOfficeTreePromise().then(function() {
                        n.initDoctors(t).then(function() {
                            n.initConsultants(t).then(function() {
                                ii();
                                ot(n.criteria.isShow);
                                i.resolve(!0)
                            })
                        })
                    }), i.promise
                },
                wt = function() {
                    h.value(null);
                    c.value(null);
                    k.value(null);
                    d.value(null);
                    g.value(null);
                    n.criteria.patientName = "";
                    n.criteria.privateId = "";
                    n.criteria.chargeItemName = "";
                    n.criteria.stepName = "";
                    n.criteria.lastDeductionDateTime = null;
                    n.criteria.executionDoctorId = null;
                    st()
                },
                ft = function(t) {
                    n.isGroup && (n.criteria.consultantId = null, n.criteria.executionDoctorId = null, t && t.length > 1 || t && t.length == 0 || !t ? (h.enable(!1), c.enable(!1)) : (h.enable(!0), c.enable(!0), b(t[0])))
                },
                et = function() {
                    var t = n.validateData();
                    t && v()
                },
                bt = function() {
                    var t = lt();
                    if (!t.length) {
                        s.warn("提示", "请选择需要分配的划扣！");
                        return
                    }
                    if (n.isAssignedFlag) {
                        s.warn("提示", "只有待执行的可以分配！");
                        return
                    }
                    if (o.isGroup && n.selectedOfficeIds && n.selectedOfficeIds.length > 1) return s.warn("提示", "划扣分配仅支持单店"), !1;
                    n.getSelectAllData(n.selectTotalCount, t, n.criteria).then(function(t) {
                        var r = n.isGroup && n.selectedOfficeIds && n.selectedOfficeIds.length == 1 ? n.selectedOfficeIds[0] : o.officeId,
                            u = i.open({
                                animation: !0,
                                backdrop: "static",
                                template: "<charge-deduction-allocation-view><\/charge-deduction-allocation-view>",
                                controller: "ChargeDeductionAllocationCtrl",
                                backdropClass: "ares-modal-backdrop",
                                resolve: {
                                    host: function() {
                                        return {
                                            chargeDeductions: t,
                                            orProviders: n.doctors,
                                            officeId: r,
                                            chargeDeductionCount: n.selectedRows
                                        }
                                    }
                                }
                            });
                        u.result.then(function(t) {
                            t && (n.selectedRows = 0, et())
                        })
                    })
                },
                kt = function() {
                    n.searchMode = !n.searchMode
                },
                dt = function() {
                    k = e.find("#sexInput").kendoDropDownList({
                        dataSource: tt,
                        dataTextField: "name",
                        dataValueField: "id",
                        optionLabel: "性别",
                        select: function(t) {
                            n.criteria.sex = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                },
                gt = function() {
                    d = e.find("#startAgeInput").kendoDropDownList({
                        dataSource: y,
                        dataTextField: "name",
                        dataValueField: "id",
                        optionLabel: "年龄",
                        select: function(t) {
                            n.criteria.startAge = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                },
                ni = function() {
                    g = e.find("#endAgeInput").kendoDropDownList({
                        dataSource: y,
                        dataTextField: "name",
                        dataValueField: "id",
                        optionLabel: "年龄",
                        select: function(t) {
                            n.criteria.endAge = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                },
                ti = function() {
                    ht = e.find("#handoverTypeInput").kendoDropDownList({
                        optionLabel: "交接人员",
                        dataSource: it,
                        dataTextField: "name",
                        dataValueField: "id",
                        select: function(t) {
                            n.criteria.endAge = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                },
                ii = function() {
                    h ? h.dataSource.data(n.consultants) : h = e.find("#consultantInput").kendoDropDownList({
                        dataSource: n.consultants,
                        filter: "contains",
                        dataTextField: "name",
                        dataValueField: "id",
                        optionLabel: "咨询师",
                        select: function(t) {
                            n.criteria.consultantId = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                },
                ot = function(t) {
                    var i = _.filter(n.doctors, function(n) {
                        return n.show == t
                    });
                    c ? c.dataSource.data(i) : c = e.find("#executionDoctorInput").kendoDropDownList({
                        dataSource: i,
                        filter: "contains",
                        dataTextField: "name",
                        dataValueField: "id",
                        optionLabel: "执行医生",
                        select: function(t) {
                            n.criteria.executionDoctorId = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList");
                    n.criteria.executionDoctorId = null
                },
                ri = function() {
                    nt.push({
                        id: 0,
                        name: "未执行"
                    });
                    nt.push({
                        id: 1,
                        name: "已执行"
                    });
                    tt = [{
                        id: 0,
                        name: "未知"
                    }, {
                        id: 1,
                        name: "男"
                    }, {
                        id: 2,
                        name: "女"
                    }];
                    for (var n = 0; n <= 100; n++) y.push({
                        id: n,
                        name: n + "岁"
                    });
                    it = [{
                        id: 0,
                        name: "医生"
                    }]
                },
                ui = function(t) {
                    var i, r;
                    n.selectedOfficeIds = t && t.length != 0 ? t.map(function(n) {
                        return n.id
                    }) : [];
                    i = n.selectedOfficeIds.length == 1 ? n.selectedOfficeIds : null;
                    i && b(i);
                    ft(n.selectedOfficeIds);
                    r = n.selectedOfficeIds && n.selectedOfficeIds.length > 1;
                    r && (n.showAllocationButton = !r)
                },
                fi = function() {
                    var t = moment().subtract(1, "week").format("YYYY-MM-DD"),
                        i = moment().add(1, "day").format("YYYY-MM-DD");
                    n.timeSpan = {
                        startDate: t,
                        endDate: i
                    }
                },
                ei = function() {
                    ot(n.criteria.isShow)
                },
                st = function() {
                    n.selectTotalCount = !1;
                    n.selectedRows = 0
                };
            (function() {
                fi();
                ri();
                n.resetSelectedRows = st;
                n.changeDoctorInput = ei;
                n.showAllocationButton = !0;
                n.onOfficeSelected = ui;
                n.onPageChanged = vt;
                n.onPageSizeChanged = yt;
                n.refresh = wt;
                n.search = et;
                n.switchMode = kt;
                n.allocationChargeDeduction = bt;
                n.onAllCheckboxClicked = at;
                pt()
            })()
        }
    }
}]);
tenantModule.directive("handoverPatientView", ["$log", "$window", "$modal", "$timeout", "$q", "kendoUtil", "gridOptionUtil", "loginContext", "aresDialog", "appNav", "aresModalShelf", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/handover/handover-patient-view.html",
        controller: "HandoverPatientCtrl",
        link: function(n, e) {
            var st = null,
                h = null,
                c = null,
                l = null,
                a = null,
                v = null,
                y = null,
                p = null,
                nt = null,
                tt = null,
                it = null,
                rt = [],
                b = [],
                k = [{
                    title: "患者姓名",
                    field: "patientName",
                    width: "85px"
                }, {
                    title: "病历号",
                    field: "privateId",
                    width: "120px"
                }, {
                    title: "性别",
                    field: "sexStr",
                    width: "60px"
                }, {
                    title: "年龄",
                    field: "ageStr",
                    width: "60px"
                }, {
                    title: "患者来源",
                    field: "sourceTypeStr",
                    width: "200px"
                }, {
                    title: "患者创建时间",
                    field: "recordCreatedTimeStr",
                    width: "120px"
                }, {
                    title: "患者创建人",
                    field: "recordCreatedUserName",
                    width: "120px"
                }, {
                    title: "责任医生",
                    field: "dutyDoctorName",
                    width: "120px"
                }, {
                    title: "咨询师",
                    field: "consultantName",
                    width: "120px"
                }, {
                    title: "网电咨询师",
                    field: "onlineConsultantName",
                    width: "120px"
                }, {
                    title: "专属客服",
                    field: "attendantName",
                    width: "85px"
                }, {
                    title: "开发人员",
                    field: "developerName",
                    width: "85px"
                }, {
                    title: "专属顾问",
                    field: "advisorName",
                    width: "85px"
                }, {
                    title: "初诊医生",
                    field: "firstVisitDoctorName",
                    width: "85px"
                }],
                d;
            n.isGroup && k.splice(0, 0, {
                title: "所属机构",
                field: "officeName",
                width: "85px"
            });
            d = f.CommonColumnsNotINHeader.checkboxColumn;
            d.locked = !0;
            k.splice(0, 0, d);
            var ut = null,
                w, g = function(i) {
                    n.refreshListData(i).then(function(i) {
                        var u, f;
                        ut = angular.copy(k);
                        u = e.find("#patientGrid");
                        u.html("");
                        f = t.innerHeight - 260 - (window.Ares3 ? 50 : 0);
                        n.handoverPatientList = i.items;
                        r(function() {
                            w = u.kendoGrid({
                                excel: {
                                    allPages: !0
                                },
                                dataSource: {
                                    data: i.items
                                },
                                height: f,
                                model: {
                                    id: "id"
                                },
                                columns: ut,
                                dataBound: ht,
                                sortable: !1,
                                resizable: !0,
                                reorderable: !0
                            }).data("kendoGrid")
                        })
                    })
                },
                ht = function() {
                    $(e).find("#patientGrid table tbody tr td .commonColumns_sub_checkbox").each(function() {
                        $(this).bind("click", function(t) {
                            var i = f.selectSingleRow(w, "patientGrid", n.pageData.items.length, this, t);
                            ct(i)
                        })
                    })
                },
                ct = function(t) {
                    n.selectedRows = t;
                    r(function() {
                        n.selectTotalCount = n.selectedRows == n.pageData.totalCount
                    })
                },
                vi = function(t) {
                    n.showColumns = t
                },
                lt = function() {
                    var t = f.getCustomSelectedData(w),
                        n = [];
                    return t.forEach(function(t) {
                        n.push(t.id)
                    }), n = _.uniq(n)
                },
                at = function(t) {
                    var i = e.find("#patientGrid"),
                        r = f.selectAllRow(w, "patientGrid", t);
                    n.selectedRows = t ? n.pageData.totalCount : 0
                },
                vt = function(t) {
                    n.criteria.pageIndex = t;
                    var i = n.validateData();
                    i && g()
                },
                yt = function(t) {
                    n.criteria.pageSize = t;
                    var i = n.validateData();
                    i && g()
                },
                pt = function() {
                    var t = u.defer();
                    return dt(), gt(), ni(), ti(), ft().then(function() {
                        ot(n.selectedOfficeIds);
                        t.resolve()
                    }), t.promise
                },
                ft = function(t) {
                    var i = u.defer();
                    return n.queryOfficeTreePromise().then(function() {
                        n.initProviderBaseData(t).then(function() {
                            ii();
                            ri();
                            ui();
                            fi();
                            oi();
                            si();
                            ei();
                            i.resolve()
                        })
                    }), i.promise
                },
                wt = function() {
                    p.value(null);
                    nt.value(null);
                    tt.value(null);
                    it.value(null);
                    n.criteria.patientName = "";
                    n.criteria.privateId = "";
                    n.criteria.handoverType = "";
                    n.criteria.sourceType = "";
                    n.criteria.advisorId = null;
                    n.criteria.attendantId = null;
                    n.criteria.consultantId = null;
                    n.criteria.developerId = null;
                    n.criteria.dutyDoctorId = null;
                    n.criteria.firstVisitDoctorId = null;
                    n.criteria.endAge = null;
                    n.criteria.onlineConsultantId = null;
                    n.criteria.sex = null;
                    n.criteria.startAge = null;
                    n.criteria.recordCreatedUser = null;
                    n.resetSelectedRows()
                },
                et = function() {
                    var t = n.validateData();
                    t && g()
                },
                bt = function() {
                    var t = lt(),
                        r;
                    if (!n.criteria.advisorId && !n.criteria.attendantId && !n.criteria.consultantId && !n.criteria.developerId && !n.criteria.dutyDoctorId && !n.criteria.onlineConsultantId && !n.criteria.firstVisitDoctorId) return s.warn("提示", "医生,咨询师，网电咨询师，专属客服，专属顾问,开发人员,初诊医生必须至少选择一个"), !1;
                    if (!t.length) {
                        s.warn("提示", "请选择需要分配的患者！");
                        return
                    }
                    if (o.isGroup && n.selectedOfficeIds && n.selectedOfficeIds.length > 1) return s.warn("提示", "划扣分配仅支持单店"), !1;
                    r = n.isGroup && n.selectedOfficeIds && n.selectedOfficeIds.length == 1 ? n.selectedOfficeIds[0] : o.officeId;
                    n.getSelectAllData(n.selectTotalCount, t, n.criteria).then(function(t) {
                        var u = i.open({
                            animation: !0,
                            backdrop: "static",
                            template: "<patient-allocation-view><\/patient-allocation-view>",
                            controller: "PatientAllocationCtrl",
                            backdropClass: "ares-modal-backdrop",
                            resolve: {
                                host: function() {
                                    return {
                                        patientIds: t,
                                        officeId: r,
                                        patientCount: t.length,
                                        handoverTypes: n.handoverType
                                    }
                                }
                            }
                        });
                        u.result.then(function(t) {
                            t && (n.selectedRows = 0, et())
                        })
                    })
                },
                kt = function() {
                    n.searchMode = !n.searchMode
                },
                dt = function() {
                    nt = e.find("#sexInput").kendoDropDownList({
                        dataSource: rt,
                        dataTextField: "name",
                        dataValueField: "id",
                        optionLabel: "性别",
                        select: function(t) {
                            n.criteria.sex = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                },
                gt = function() {
                    tt = e.find("#startAgeInput").kendoDropDownList({
                        dataSource: b,
                        dataTextField: "name",
                        dataValueField: "id",
                        optionLabel: "年龄",
                        select: function(t) {
                            n.criteria.startAge = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                },
                ni = function() {
                    it = e.find("#endAgeInput").kendoDropDownList({
                        dataSource: b,
                        dataTextField: "name",
                        dataValueField: "id",
                        optionLabel: "年龄",
                        select: function(t) {
                            n.criteria.endAge = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                },
                ti = function() {
                    st = e.find("#handoverTypeInput").kendoDropDownList({
                        optionLabel: "交接人员类型",
                        dataSource: n.handoverTypeList,
                        dataTextField: "name",
                        dataValueField: "id",
                        select: function(t) {
                            n.criteria.handoverType = this.dataItem(t.item)[this.options.dataValueField];
                            n.$apply()
                        }
                    }).data("kendoDropDownList")
                },
                ii = function() {
                    l ? l.dataSource.data(n.doctors) : l = e.find("#dutyDoctorInput").kendoDropDownList({
                        dataSource: n.doctors,
                        filter: "contains",
                        dataTextField: "name",
                        dataValueField: "id",
                        optionLabel: "医生",
                        select: function(t) {
                            n.criteria.dutyDoctorId = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                },
                ri = function() {
                    h ? h.dataSource.data(n.consultants) : h = e.find("#consultantInput").kendoDropDownList({
                        dataSource: n.consultants,
                        filter: "contains",
                        dataTextField: "name",
                        dataValueField: "id",
                        optionLabel: "咨询师",
                        select: function(t) {
                            n.criteria.consultantId = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                },
                ui = function() {
                    c ? c.dataSource.data(n.onlineConsultants) : c = e.find("#onlineConsultantInput").kendoDropDownList({
                        dataSource: n.onlineConsultants,
                        filter: "contains",
                        dataTextField: "name",
                        dataValueField: "id",
                        optionLabel: "网电咨询师",
                        select: function(t) {
                            n.criteria.onlineConsultantId = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                },
                fi = function() {
                    a ? a.dataSource.data(n.attendants) : a = e.find("#attendantInput").kendoDropDownList({
                        dataSource: n.attendants,
                        filter: "contains",
                        dataTextField: "name",
                        dataValueField: "id",
                        optionLabel: "专属客服",
                        select: function(t) {
                            n.criteria.attendantId = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                },
                ei = function() {
                    p ? p.dataSource.data(n.providers) : p = e.find("#createUserInput").kendoDropDownList({
                        dataSource: n.providers,
                        filter: "contains",
                        dataTextField: "name",
                        dataValueField: "id",
                        max: 10,
                        optionLabel: "患者创建人",
                        select: function(t) {
                            n.criteria.recordCreatedUser = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                },
                oi = function() {
                    var t = [];
                    angular.forEach(n.doctors, function(n) {
                        t.push({
                            id: n.id,
                            name: n.name
                        })
                    });
                    angular.forEach(n.consultants, function(n) {
                        t.push({
                            id: n.id,
                            name: n.name
                        })
                    });
                    n.advisors = t;
                    v ? v.dataSource.data(n.advisors) : v = e.find("#advisorInput").kendoDropDownList({
                        dataSource: n.advisors,
                        filter: "contains",
                        dataTextField: "name",
                        dataValueField: "id",
                        optionLabel: "专属顾问",
                        select: function(t) {
                            n.criteria.advisorId = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                },
                si = function() {
                    y ? y.dataSource.data(n.developers) : y = e.find("#developerInput").kendoDropDownList({
                        dataSource: {
                            data: n.developers,
                            pageSize: 10
                        },
                        filter: "contains",
                        dataTextField: "name",
                        pageable: {
                            pageSizes: 10
                        },
                        dataValueField: "id",
                        optionLabel: "开发人员",
                        select: function(t) {
                            n.criteria.developerId = this.dataItem(t.item)[this.options.dataValueField]
                        }
                    }).data("kendoDropDownList")
                },
                hi = function() {
                    n.handoverType = [];
                    rt = [{
                        id: 0,
                        name: "未知"
                    }, {
                        id: 1,
                        name: "男"
                    }, {
                        id: 2,
                        name: "女"
                    }];
                    for (var t = 0; t <= 100; t++) b.push({
                        id: t,
                        name: t + "岁"
                    });
                    n.handoverTypeList = [{
                        id: 0,
                        name: "责任医生"
                    }, {
                        id: 1,
                        name: "咨询师"
                    }, {
                        id: 2,
                        name: "网电咨询师"
                    }, {
                        id: 3,
                        name: "专属客服"
                    }, {
                        id: 4,
                        name: "专属顾问"
                    }, {
                        id: 5,
                        name: "开发人员"
                    }, {
                        id: 6,
                        name: "初诊医生"
                    }]
                },
                ci = function(t) {
                    n.selectedOfficeIds = t && t.length != 0 ? t.map(function(n) {
                        return n.id
                    }) : [];
                    ot(n.selectedOfficeIds);
                    var r = n.selectedOfficeIds.length == 1 ? n.selectedOfficeIds : null,
                        i = n.selectedOfficeIds && n.selectedOfficeIds.length > 1;
                    n.showAllocationButton = !i
                },
                li = function() {
                    var t = moment().subtract(1, "month").format("YYYY-MM-DD"),
                        i = moment().add(1, "day").format("YYYY-MM-DD");
                    n.timeSpan = {
                        startDate: t,
                        endDate: i
                    }
                },
                ot = function(t) {
                    n.isGroup && (n.criteria.dutyDoctorId = null, n.criteria.consultantId = null, n.criteria.onlineConsultantId = null, n.criteria.attendantId = null, n.criteria.advisorId = null, n.criteria.developerId = null, t && t.length > 1 || t && t.length == 0 || !t ? (h.enable(!1), c.enable(!1), l.enable(!1), a.enable(!1), v.enable(!1), y.enable(!1)) : (h.enable(!0), c.enable(!0), l.enable(!0), a.enable(!0), v.enable(!0), y.enable(!0), ft(t[0])))
                },
                ai = function() {
                    n.selectTotalCount = !1;
                    n.selectedRows = 0
                };
            (function() {
                hi();
                li();
                n.resetSelectedRows = ai;
                n.showAllocationButton = !0;
                n.onOfficeSelected = ci;
                n.onPageChanged = vt;
                n.onPageSizeChanged = yt;
                n.refresh = wt;
                n.search = et;
                n.switchMode = kt;
                n.allocationPatient = bt;
                n.onAllCheckboxClicked = at;
                n.isAres3 = window.Ares3;
                pt().then(function() {})
            })()
        }
    }
}]);
tenantModule.directive("officeSettingBusinessRuleView", ["$log", "$timeout", "$state", function() {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/tenant/views/office-setting/office-setting-business-rule-view.html",
        controller: "OfficeSettingBusinessRuleCtrl",
        link: function(n) {
            var t = [],
                i = function() {},
                r = function() {},
                u = function() {},
                f = function(n) {
                    angular.isFunction(n) && t.push(n)
                },
                e = function() {
                    t.forEach(function(n) {
                        n()
                    })
                };
            (function() {
                n.onStartEdit = i;
                n.onSaveEdit = r;
                n.onCancelEdit = u;
                n.initViewHandleRegister = f;
                n.initData().then(function() {
                    e()
                })
            })()
        }
    }
}]);